Skip to content
Snippets Groups Projects
Unverified Commit 82482f41 authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:bug: (autocomplete) show 'create payee' only if no payee matched (#881)

parent 88fb95b2
No related branches found
No related tags found
No related merge requests found
...@@ -85,21 +85,21 @@ export default function PayeeAutocomplete({ ...@@ -85,21 +85,21 @@ export default function PayeeAutocomplete({
? allOptions.filter(item => value.includes(item.value)) ? allOptions.filter(item => value.includes(item.value))
: allOptions.find(item => item.value === value) : allOptions.find(item => item.value === value)
} }
isValidNewOption={input => input && !focusTransferPayees} isValidNewOption={input => {
if (focusTransferPayees || !input) {
return false;
}
const lowercaseInput = input.toLowerCase();
const hasExistingOption = allOptions.some(
option => option.label.toLowerCase() === lowercaseInput,
);
return !hasExistingOption;
}}
isMulti={multi} isMulti={multi}
onSelect={onSelect} onSelect={onSelect}
onCreateOption={async selectedValue => { onCreateOption={async selectedValue => {
const existingOption = allOptions.find(option =>
option.label.toLowerCase().includes(selectedValue?.toLowerCase()),
);
// Prevent creating duplicates
if (existingOption) {
onSelect(existingOption.value);
return;
}
// This is actually a new option, so create it
onSelect(await dispatch(createPayee(selectedValue))); onSelect(await dispatch(createPayee(selectedValue)));
}} }}
createOptionPosition="first" createOptionPosition="first"
......
---
category: Bugfix
authors: [MatissJanis]
---
Autocomplete: do not show "create payee" option if the typed-in payee is an exact match of an existing payee
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment