|
@ -9,7 +9,7 @@ import { |
|
|
OnInit, |
|
|
OnInit, |
|
|
ViewChild |
|
|
ViewChild |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { FormControl, NgControl, Validators } from '@angular/forms'; |
|
|
import { FormControl, NgControl } from '@angular/forms'; |
|
|
import { |
|
|
import { |
|
|
MatAutocomplete, |
|
|
MatAutocomplete, |
|
|
MatAutocompleteSelectedEvent |
|
|
MatAutocompleteSelectedEvent |
|
@ -25,7 +25,8 @@ import { |
|
|
debounceTime, |
|
|
debounceTime, |
|
|
distinctUntilChanged, |
|
|
distinctUntilChanged, |
|
|
filter, |
|
|
filter, |
|
|
switchMap |
|
|
switchMap, |
|
|
|
|
|
takeUntil |
|
|
} from 'rxjs/operators'; |
|
|
} from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
import { AbstractMatFormField } from './abstract-mat-form-field'; |
|
|
import { AbstractMatFormField } from './abstract-mat-form-field'; |
|
@ -76,12 +77,18 @@ export class SymbolAutocompleteComponent |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
super.required = this.ngControl.control?.hasValidator(Validators.required); |
|
|
|
|
|
|
|
|
|
|
|
if (this.disabled) { |
|
|
if (this.disabled) { |
|
|
this.control.disable(); |
|
|
this.control.disable(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.control.valueChanges |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe(() => { |
|
|
|
|
|
if (super.value) { |
|
|
|
|
|
super.value.dataSource = null; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.control.valueChanges |
|
|
this.control.valueChanges |
|
|
.pipe( |
|
|
.pipe( |
|
|
debounceTime(400), |
|
|
debounceTime(400), |
|
@ -89,6 +96,7 @@ export class SymbolAutocompleteComponent |
|
|
filter((query) => { |
|
|
filter((query) => { |
|
|
return isString(query) && query.length > 1; |
|
|
return isString(query) && query.length > 1; |
|
|
}), |
|
|
}), |
|
|
|
|
|
takeUntil(this.unsubscribeSubject), |
|
|
tap(() => { |
|
|
tap(() => { |
|
|
this.isLoading = true; |
|
|
this.isLoading = true; |
|
|
|
|
|
|
|
@ -136,11 +144,6 @@ export class SymbolAutocompleteComponent |
|
|
public ngDoCheck() { |
|
|
public ngDoCheck() { |
|
|
if (this.ngControl) { |
|
|
if (this.ngControl) { |
|
|
this.validateRequired(); |
|
|
this.validateRequired(); |
|
|
|
|
|
|
|
|
if (this.control.touched) { |
|
|
|
|
|
this.validateSelection(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.errorState = this.ngControl.invalid && this.ngControl.touched; |
|
|
this.errorState = this.ngControl.invalid && this.ngControl.touched; |
|
|
this.stateChanges.next(); |
|
|
this.stateChanges.next(); |
|
|
} |
|
|
} |
|
@ -173,13 +176,4 @@ export class SymbolAutocompleteComponent |
|
|
this.ngControl.control.setErrors({ invalidData: true }); |
|
|
this.ngControl.control.setErrors({ invalidData: true }); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private validateSelection() { |
|
|
|
|
|
const error = |
|
|
|
|
|
!this.isValueInOptions(this.input?.value) || |
|
|
|
|
|
this.input?.value !== super.value?.symbol; |
|
|
|
|
|
if (error) { |
|
|
|
|
|
this.ngControl.control.setErrors({ invalidData: true }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|