Skip to content

Commit

Permalink
fix: trim keyword search input
Browse files Browse the repository at this point in the history
  • Loading branch information
dmijatovic committed Oct 21, 2022
1 parent e3074a8 commit dae07c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions frontend/components/form/AsyncAutocompleteSC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export default function AsyncAutocompleteSC<T>({status, options, config,
newInputValue!==''
) {
// debugger
// issue search requestion AND
// set value as processing
onSearch(searchFor)
// issue search request using trimmed value
onSearch(searchFor.trim())
// set raw value as processing
setProcessing(searchFor)
}
}, [searchFor, foundFor, processing, newInputValue, config.minLength, onSearch])
Expand All @@ -102,9 +102,10 @@ export default function AsyncAutocompleteSC<T>({status, options, config,
// if the length is sufficient
// and we are not loading api responses
// AND onCreate method is provided
if (value.length >= config.minLength &&
if (value.trim().length >= config.minLength &&
loading === false && onCreate) {
onCreate(value)
// we send trimmed value
onCreate(value.trim())
if (config?.reset) {
// reset selected value to nothing
setSelected(null)
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/keyword/FindKeyword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function FindKeyword({config, onAdd, searchForKeyword, onCreate}:
return (
<li {...props} key={option.key}>
{/* if new option (has input) show label and count */}
<strong>{`Add "${option.label}"`}</strong>
<strong>{`Add "${option.label.trim()}"`}</strong>
</li>
)
}
Expand All @@ -91,7 +91,7 @@ export default function FindKeyword({config, onAdd, searchForKeyword, onCreate}:
// when value is not not found option returns input prop
if (option?.input && onCreate) {
// if input is over minLength
if (option?.input.length > config.minLength) {
if (option?.input.trim().length > config.minLength) {
// we offer an option to create this entry
return renderAddOption(props,option)
} else {
Expand Down

0 comments on commit dae07c5

Please sign in to comment.