autocomplete fix
This commit is contained in:
parent
d70e8d46c5
commit
c8600b315e
|
@ -135,16 +135,16 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
|
|||
|
||||
getSelectedItems(value: any) {
|
||||
if (value != null && Array.isArray(value) && this.configuration) {
|
||||
const newSelections = value.filter(x => !this._selectedItems.has(JSON.stringify(x)));
|
||||
const newSelections = value.filter(x => !this._selectedItems.has(this.stringify(x)));
|
||||
if (newSelections.length > 0 && this.configuration.getSelectedItems != null) {
|
||||
this.configuration.getSelectedItems(newSelections).pipe(takeUntil(this._destroyed)).subscribe(x => {
|
||||
x.forEach(element => {
|
||||
this._selectedItems.set(JSON.stringify(this.configuration.valueAssign != null ? this.configuration.valueAssign(element) : element), element);
|
||||
this._selectedItems.set(this.stringify(this.configuration.valueAssign != null ? this.configuration.valueAssign(element) : element), element);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
newSelections.forEach(element => {
|
||||
this._selectedItems.set(JSON.stringify(this.configuration.valueAssign != null ? this.configuration.valueAssign(element) : element), element);
|
||||
this._selectedItems.set(this.stringify(this.configuration.valueAssign != null ? this.configuration.valueAssign(element) : element), element);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
|
|||
}
|
||||
|
||||
stringify(value: any): string {
|
||||
return JSON.stringify(value);
|
||||
return typeof (value) == 'string' ? value : JSON.stringify(value);
|
||||
}
|
||||
|
||||
isNullOrEmpty(query: string): boolean {
|
||||
|
@ -182,7 +182,7 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
|
|||
const newValue = this._valueToAssign(item);
|
||||
|
||||
//Update selected items
|
||||
this._selectedItems.set(JSON.stringify(newValue), item);
|
||||
this._selectedItems.set(this.stringify(newValue), item);
|
||||
|
||||
const newValueArray = (Array.isArray(this.value) ? this.value : []);
|
||||
newValueArray.push(newValue);
|
||||
|
@ -319,11 +319,11 @@ export class MultipleAutoCompleteComponent extends _CustomComponentMixinBase imp
|
|||
_removeSelectedItem(item: any, event: MouseEvent): void {
|
||||
if (event != null) { event.stopPropagation(); }
|
||||
const valueToDelete = this._valueToAssign(item);
|
||||
this.value = this.value.filter(x => JSON.stringify(x) !== JSON.stringify(valueToDelete)); //TODO, maybe we need to implement equality here differently.
|
||||
this.value = this.value.filter(x => this.stringify(x) !== this.stringify(valueToDelete)); //TODO, maybe we need to implement equality here differently.
|
||||
this.optionRemoved.emit(item);
|
||||
|
||||
//Update chips
|
||||
this._selectedItems.delete(JSON.stringify(valueToDelete));
|
||||
this._selectedItems.delete(this.stringify(valueToDelete));
|
||||
|
||||
this.autocompleteInput.nativeElement.focus();
|
||||
this.pushChanges(this.value);
|
||||
|
|
|
@ -72,9 +72,9 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
|||
this.multipleAutoCompleteConfiguration = {
|
||||
filterFn: this.searchFromAutocomplete.bind(this),
|
||||
initialItems: () => this.searchFromAutocomplete(''),
|
||||
displayFn: (item) => item['label'],
|
||||
titleFn: (item) => item['label'],
|
||||
valueAssign: this._transformValue,
|
||||
displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label'],
|
||||
titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label'],
|
||||
valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item),
|
||||
subtitleFn: (item) => item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE')
|
||||
}
|
||||
}
|
||||
|
@ -111,11 +111,6 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
|||
// }
|
||||
// }
|
||||
|
||||
_transformValue(item: any) {
|
||||
if (!item) return [];
|
||||
return item && typeof item === 'string' ? JSON.parse(item) : JSON.stringify(item);
|
||||
}
|
||||
|
||||
searchFromAutocomplete(query: string) {
|
||||
const autocompleteRequestItem: RequestItem<DatasetExternalAutocompleteCriteria> = new RequestItem();
|
||||
autocompleteRequestItem.criteria = new DatasetExternalAutocompleteCriteria();
|
||||
|
@ -164,9 +159,9 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
|||
this.multipleAutoCompleteConfiguration = {
|
||||
filterFn: myfunc.bind(this),
|
||||
initialItems: (extraData) => myfunc(''),
|
||||
displayFn: (item) => item[title],
|
||||
titleFn: (item) => item[title],
|
||||
valueAssign: this._transformValue,
|
||||
displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label'],
|
||||
titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label'],
|
||||
valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item),
|
||||
subtitleFn: (item) => item[subtitle]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue