From 9da6544f8ba76b4b74797cdc60ee22430035bab0 Mon Sep 17 00:00:00 2001 From: Mark Pittaway Date: Thu, 19 Oct 2023 10:21:26 +1100 Subject: [PATCH] [SDESK-7062] improve: Use includes instead of startsWith for Autocomplete suggestions --- client/components/fields/editor/base/text.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/components/fields/editor/base/text.tsx b/client/components/fields/editor/base/text.tsx index 7376d2622..c2764b070 100644 --- a/client/components/fields/editor/base/text.tsx +++ b/client/components/fields/editor/base/text.tsx @@ -31,6 +31,7 @@ export class EditorFieldText extends React.Component> { const {httpRequestJsonLocal} = superdeskApi; return httpRequestJsonLocal>({ @@ -92,10 +93,22 @@ export class EditorFieldText extends React.Component response._items.map((_item) => _item.value).filter((value) => !!value), (reason) => { console.warn(reason); + return []; } ); } + searchSuggestions(searchString: string, callback: (result: Array) => void) { + const currentValue = get(this.props.item, this.props.field); + + callback(this.state.suggestions.filter( + (name) => name.toLowerCase().includes(searchString) && name.toLowerCase() !== currentValue + )); + + // eslint-disable-next-line no-empty-function + return {cancel: () => {}}; + } + render() { const field = this.props.field; const value = get(this.props.item, field, this.props.defaultValue); @@ -134,6 +147,7 @@ export class EditorFieldText extends React.Component )}