Browse Source

UI: Improvement for entity autocomplete

pull/8929/head
Artem Dzhereleiko 3 years ago
parent
commit
b076a89b58
  1. 12
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

12
ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

@ -26,7 +26,7 @@ import {
ViewChild
} from '@angular/core';
import { MatFormFieldAppearance } from '@angular/material/form-field';
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { merge, Observable, of, Subject } from 'rxjs';
import { catchError, debounceTime, map, share, switchMap, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store';
@ -55,7 +55,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
selectEntityFormGroup: UntypedFormGroup;
modelValue: string | null;
modelValue: string | EntityId | null;
entityTypeValue: EntityType | AliasEntityType;
@ -113,6 +113,10 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
@Input()
requiredText: string;
@Input()
@coerceBoolean()
useFullEntityId: boolean;
@Input()
appearance: MatFormFieldAppearance = 'fill';
@ -171,7 +175,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
if (typeof value === 'string' || !value) {
modelValue = null;
} else {
modelValue = value.id.id;
modelValue = this.useFullEntityId ? value.id : value.id.id;
}
this.updateView(modelValue, value);
if (value === null) {
@ -307,7 +311,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
} catch (e) {
this.propagateChange(null);
}
this.modelValue = entity !== null ? entity.id.id : null;
this.modelValue = entity !== null ? (this.useFullEntityId ? entity.id : entity.id.id) : null;
this.selectEntityFormGroup.get('entity').patchValue(entity !== null ? entity : '', {emitEvent: false});
this.entityChanged.emit(entity);
} else {

Loading…
Cancel
Save