From e853c8c44ac194163945e15fb29d04e7f81e02f6 Mon Sep 17 00:00:00 2001 From: gkolokythas Date: Thu, 19 Sep 2019 18:05:20 +0300 Subject: [PATCH] Adds clear autocomplete when you select value functionality at External References. (Issue #155) --- .../single/single-auto-complete-configuration.ts | 2 ++ .../auto-complete/single/single-auto-complete.component.ts | 7 +++++++ .../dataset-external-references-editor.component.ts | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts index d90d89a58..6628279f6 100644 --- a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts +++ b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts @@ -8,6 +8,8 @@ export interface SingleAutoCompleteConfiguration { minFilteringChars?: number; // Load and present items from start, without user query. Default: true. loadDataOnStart?: boolean; + // Remove item after selection. + removeAfterSelection?: boolean; // Static or initial items. initialItems?: (data?: any) => Observable; // Data retrieval function diff --git a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts index 1d740aefb..7acfe607f 100644 --- a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts +++ b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts @@ -153,6 +153,13 @@ export class SingleAutoCompleteComponent implements OnInit, MatFormFieldControl< //this._inputValue = " "; this.stateChanges.next(); this.optionSelected.emit(event.option.value); + if (this.configuration.removeAfterSelection) { + this.clearAutocomplete() + } + } + + private clearAutocomplete() { + this._setValue(null); } private _setValue(value: any) { diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts index d4894cf99..d68a70254 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts @@ -66,6 +66,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl this.dataRepositoriesAutoCompleteConfiguration = { filterFn: this.searchDatasetExternalDataRepositories.bind(this), + removeAfterSelection: true, initialItems: (type) => this.searchDatasetExternalDataRepositories('', type), displayFn: (item) => item ? item.name : null, titleFn: (item) => item ? item.name : null, @@ -74,6 +75,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl this.externalDatasetAutoCompleteConfiguration = { filterFn: this.searchDatasetExternalDatasets.bind(this), + removeAfterSelection: true, initialItems: (type) => this.searchDatasetExternalDatasets('', type),//.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1), displayFn: (item) => item ? item.label : null, titleFn: (item) => item ? item.label : null, @@ -82,6 +84,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl this.registriesAutoCompleteConfiguration = { filterFn: this.searchDatasetExternalRegistries.bind(this), + removeAfterSelection: true, initialItems: (type) => this.searchDatasetExternalRegistries('', type), displayFn: (item) => item ? item.label : null, titleFn: (item) => item ? item.label: null, @@ -90,6 +93,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl this.servicesAutoCompleteConfiguration = { filterFn: this.searchDatasetExternalServices.bind(this), + removeAfterSelection: true, initialItems: (type) => this.searchDatasetExternalServices('', type), displayFn: (item) => item ? item.label : null, titleFn: (item) => item ? item.label : null, @@ -98,6 +102,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl this.tagsAutoCompleteConfiguration = { filterFn: this.searchDatasetTags.bind(this), + removeAfterSelection: true, initialItems: (type) => this.searchDatasetTags('', type), displayFn: (item) => item ? item.name : null, titleFn: (item) => item ? item.name : null,