Skip to content

Commit

Permalink
fix: do not try to find match in available options when add new item …
Browse files Browse the repository at this point in the history
…is selected by user.
  • Loading branch information
dmijatovic committed Aug 25, 2022
1 parent 31b94b7 commit a6490c2
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions frontend/components/form/AsyncAutocompleteSC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,10 @@ export default function AsyncAutocompleteSC<T>({status, options, config,
// create request is allowed only
// if the length is sufficient
// and we are not loading api responses
// AND onCreate method is provided
if (value.length >= config.minLength &&
loading === false) {
// console.log('requestCreate...', value)
if (options.length > 0) {
// try to find item in the options
const foundItems = options.filter(item => item.label.toLocaleLowerCase() === value.toLocaleLowerCase())
if (foundItems.length > 0) {
// if we found item in available options
// we use it
onAdd(foundItems[0])
} else if (onCreate) {
// otherwise we create item
onCreate(value)
}
} else if (onCreate) {
onCreate(value)
}
loading === false && onCreate) {
onCreate(value)
if (config?.reset) {
// reset selected value to nothing
setSelected(null)
Expand Down

0 comments on commit a6490c2

Please sign in to comment.