|
|
@ -21,7 +21,7 @@ import { |
|
|
import { |
|
|
import { |
|
|
MatAutocomplete, |
|
|
MatAutocomplete, |
|
|
MatAutocompleteModule, |
|
|
MatAutocompleteModule, |
|
|
MatAutocompleteSelectedEvent |
|
|
MatOption |
|
|
} from '@angular/material/autocomplete'; |
|
|
} from '@angular/material/autocomplete'; |
|
|
import { |
|
|
import { |
|
|
MatFormFieldControl, |
|
|
MatFormFieldControl, |
|
|
@ -58,18 +58,18 @@ import { AbstractMatFormField } from '../shared/abstract-mat-form-field'; |
|
|
templateUrl: 'currency-selector.component.html' |
|
|
templateUrl: 'currency-selector.component.html' |
|
|
}) |
|
|
}) |
|
|
export class GfCurrencySelectorComponent |
|
|
export class GfCurrencySelectorComponent |
|
|
extends AbstractMatFormField<string> |
|
|
extends AbstractMatFormField<string | null> |
|
|
implements DoCheck, OnDestroy, OnInit |
|
|
implements DoCheck, OnDestroy, OnInit |
|
|
{ |
|
|
{ |
|
|
|
|
|
@ViewChild('currencyAutocomplete') |
|
|
|
|
|
public currencyAutocomplete: MatAutocomplete; |
|
|
|
|
|
|
|
|
@Input() private currencies: string[] = []; |
|
|
@Input() private currencies: string[] = []; |
|
|
@Input() private formControlName: string; |
|
|
@Input() private formControlName: string; |
|
|
|
|
|
|
|
|
@ViewChild(MatInput) private input: MatInput; |
|
|
@ViewChild(MatInput) private input: MatInput; |
|
|
|
|
|
|
|
|
@ViewChild('currencyAutocomplete') |
|
|
public control = new FormControl<string | null>(null); |
|
|
public currencyAutocomplete: MatAutocomplete; |
|
|
|
|
|
|
|
|
|
|
|
public control = new FormControl(); |
|
|
|
|
|
public filteredCurrencies: string[] = []; |
|
|
public filteredCurrencies: string[] = []; |
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
@ -86,6 +86,19 @@ export class GfCurrencySelectorComponent |
|
|
this.controlType = 'currency-selector'; |
|
|
this.controlType = 'currency-selector'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public get empty() { |
|
|
|
|
|
return this.input?.empty; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public set value(value: string | null) { |
|
|
|
|
|
this.control.setValue(value); |
|
|
|
|
|
super.value = value; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public focus() { |
|
|
|
|
|
this.input.focus(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
if (this.disabled) { |
|
|
if (this.disabled) { |
|
|
this.control.disable(); |
|
|
this.control.disable(); |
|
|
@ -97,9 +110,10 @@ export class GfCurrencySelectorComponent |
|
|
const control = formGroup.get(this.formControlName); |
|
|
const control = formGroup.get(this.formControlName); |
|
|
|
|
|
|
|
|
if (control) { |
|
|
if (control) { |
|
|
this.value = this.currencies.find((value) => { |
|
|
this.value = |
|
|
|
|
|
this.currencies.find((value) => { |
|
|
return value === control.value; |
|
|
return value === control.value; |
|
|
}); |
|
|
}) ?? null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -124,29 +138,16 @@ export class GfCurrencySelectorComponent |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public get empty() { |
|
|
|
|
|
return this.input?.empty; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public focus() { |
|
|
|
|
|
this.input.focus(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ngDoCheck() { |
|
|
public ngDoCheck() { |
|
|
if (this.ngControl) { |
|
|
if (this.ngControl) { |
|
|
this.validateRequired(); |
|
|
this.validateRequired(); |
|
|
this.errorState = this.ngControl.invalid && this.ngControl.touched; |
|
|
this.errorState = !!(this.ngControl.invalid && this.ngControl.touched); |
|
|
this.stateChanges.next(); |
|
|
this.stateChanges.next(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onUpdateCurrency(event: MatAutocompleteSelectedEvent) { |
|
|
public onUpdateCurrency({ option }: { option: MatOption<string> }) { |
|
|
super.value = event.option.value; |
|
|
super.value = option.value; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public set value(value: string) { |
|
|
|
|
|
this.control.setValue(value); |
|
|
|
|
|
super.value = value; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
public ngOnDestroy() { |
|
|
@ -157,7 +158,7 @@ export class GfCurrencySelectorComponent |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private filter(value: string) { |
|
|
private filter(value: string) { |
|
|
const filterValue = value?.toLowerCase(); |
|
|
const filterValue = value.toLowerCase(); |
|
|
|
|
|
|
|
|
return this.currencies.filter((currency) => { |
|
|
return this.currencies.filter((currency) => { |
|
|
return currency.toLowerCase().startsWith(filterValue); |
|
|
return currency.toLowerCase().startsWith(filterValue); |
|
|
@ -168,7 +169,7 @@ export class GfCurrencySelectorComponent |
|
|
const requiredCheck = super.required ? !super.value : false; |
|
|
const requiredCheck = super.required ? !super.value : false; |
|
|
|
|
|
|
|
|
if (requiredCheck) { |
|
|
if (requiredCheck) { |
|
|
this.ngControl.control.setErrors({ invalidData: true }); |
|
|
this.ngControl.control?.setErrors({ invalidData: true }); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|