Skip to content

Commit

Permalink
validando busca para evitar busca somente com *
Browse files Browse the repository at this point in the history
  • Loading branch information
jesielviana committed Dec 4, 2023
1 parent 20c165d commit ed92852
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/AdvancedSearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ const AdvancedSearchBox = ({
return fullQuery;
}

function validSearch() {
let valid = query ? query.length > 2 : false;
if (valid) {
return true;
}
inputs.forEach((input) => {
if (input.value ? input.value.length > 2 : false) {
valid = true;
return;
}
});
console.log('disabled', valid);
return valid;
}

useEffect(() => {
ElasticSearchStatsService(indexName)
.then((res) => {
Expand Down Expand Up @@ -105,7 +120,11 @@ const AdvancedSearchBox = ({
}}
view={({ onSubmit }) => (
<form onSubmit={onSubmit} className="d-flex flex-gap-8 align-items-center sui-search-box ">
<button type="submit" className="button sui-search-box__submit d-flex align-items-center flex-gap-8">
<button
disabled={!validSearch()}
type="submit"
className="button sui-search-box__submit d-flex align-items-center flex-gap-8"
>
<IoSearch />
{t('Search')}
</button>
Expand Down

0 comments on commit ed92852

Please sign in to comment.