Browse Source

Fix for autocompletion.

pull/350/head
Sebastian Stehle 7 years ago
parent
commit
d27761d907
  1. 16
      src/Squidex/app/framework/angular/forms/autocomplete.component.ts

16
src/Squidex/app/framework/angular/forms/autocomplete.component.ts

@ -21,6 +21,8 @@ const KEY_ESCAPE = 27;
const KEY_UP = 38; const KEY_UP = 38;
const KEY_DOWN = 40; const KEY_DOWN = 40;
const NO_EMIT = { emitEvent: false };
export const SQX_AUTOCOMPLETE_CONTROL_VALUE_ACCESSOR: any = { export const SQX_AUTOCOMPLETE_CONTROL_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => AutocompleteComponent), multi: true provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => AutocompleteComponent), multi: true
}; };
@ -118,9 +120,9 @@ export class AutocompleteComponent extends StatefulControlComponent<State, any[]
this.resetForm(); this.resetForm();
} else { } else {
if (this.displayProperty && this.displayProperty.length > 0) { if (this.displayProperty && this.displayProperty.length > 0) {
this.queryInput.setValue(obj[this.displayProperty]); this.queryInput.setValue(obj[this.displayProperty], NO_EMIT);
} else { } else {
this.queryInput.setValue(obj.toString()); this.queryInput.setValue(obj.toString(), NO_EMIT);
} }
} }
@ -130,9 +132,9 @@ export class AutocompleteComponent extends StatefulControlComponent<State, any[]
public setDisabledState(isDisabled: boolean): void { public setDisabledState(isDisabled: boolean): void {
if (isDisabled) { if (isDisabled) {
this.reset(); this.reset();
this.queryInput.disable(); this.queryInput.disable(NO_EMIT);
} else { } else {
this.queryInput.enable(); this.queryInput.enable(NO_EMIT);
} }
} }
@ -165,9 +167,9 @@ export class AutocompleteComponent extends StatefulControlComponent<State, any[]
if (selection) { if (selection) {
try { try {
if (this.displayProperty && this.displayProperty.length > 0) { if (this.displayProperty && this.displayProperty.length > 0) {
this.queryInput.setValue(selection[this.displayProperty], { emitEvent: false }); this.queryInput.setValue(selection[this.displayProperty], NO_EMIT);
} else { } else {
this.queryInput.setValue(selection.toString(), { emitEvent: false }); this.queryInput.setValue(selection.toString(), NO_EMIT);
} }
this.callChange(selection); this.callChange(selection);
} finally { } finally {
@ -201,7 +203,7 @@ export class AutocompleteComponent extends StatefulControlComponent<State, any[]
} }
private resetForm() { private resetForm() {
this.queryInput.setValue(''); this.queryInput.setValue('', NO_EMIT);
} }
private reset() { private reset() {

Loading…
Cancel
Save