Browse Source

review changes

- bugfix: avoid set value to undefined
- filter by startsWith instead include
pull/2429/head
Kevin Lien 2 years ago
committed by Thomas
parent
commit
755d56a8e8
  1. 10
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

10
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

@ -110,23 +110,25 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
const matchingEntry = this.platforms.find(({ name }) => { const matchingEntry = this.platforms.find(({ name }) => {
return name === inputValue; return name === inputValue;
}); });
this.accountForm.controls['platformId'].setValue(matchingEntry); if (matchingEntry) {
this.accountForm.controls['platformId'].setValue(matchingEntry);
}
} }
} }
displayFn(platform: Platform) { public displayFn(platform: Platform) {
return platform?.name ? platform.name : ''; return platform?.name ? platform.name : '';
} }
private _filter(value: string): Platform[] { private _filter(value: string): Platform[] {
const filterValue = value.toLowerCase(); const filterValue = value.toLowerCase();
return this.platforms.filter(({ name }) => { return this.platforms.filter(({ name }) => {
return name.toLowerCase().includes(filterValue); return name.toLowerCase().startsWith(filterValue);
}); });
} }
private _autocompleteObjectValidator(): ValidatorFn { private _autocompleteObjectValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => { return (control: AbstractControl) => {
if (typeof control.value === 'string') { if (typeof control.value === 'string') {
return { invalidAutocompleteObject: { value: control.value } }; return { invalidAutocompleteObject: { value: control.value } };
} }

Loading…
Cancel
Save