refactor: refs #8647 simplify filter handling logic in VnSelect component
gitea/salix-front/pipeline/pr-dev This commit is unstable Details

This commit is contained in:
Jorge Penadés 2025-03-06 12:12:26 +01:00
parent 73b73cba62
commit 13a904290c
1 changed files with 22 additions and 19 deletions

View File

@ -251,26 +251,29 @@ async function filterHandler(val, update) {
if ($props.filterFn) update($props.filterFn(val));
else if (!val && lastVal.value === val) update();
else if (
$props.url &&
($props.limit || (!$props.limit && Object.keys(myOptions.value).length === 0))
) {
newOptions = await fetchFilter(val);
} else newOptions = filter(val, myOptionsOriginal.value);
update(
() => {
if ($props.noOne && noOneText.toLowerCase().includes(val.toLowerCase()))
newOptions.unshift(noOneOpt.value);
else {
const makeRequest =
($props.url && $props.limit) ||
(!$props.limit && Object.keys(myOptions.value).length === 0);
newOptions = makeRequest
? await fetchFilter(val)
: filter(val, myOptionsOriginal.value);
myOptions.value = newOptions;
},
(ref) => {
if (val !== '' && ref.options.length > 0) {
ref.setOptionIndex(-1);
ref.moveOptionSelection(1, true);
}
},
);
update(
() => {
if ($props.noOne && noOneText.toLowerCase().includes(val.toLowerCase()))
newOptions.unshift(noOneOpt.value);
myOptions.value = newOptions;
},
(ref) => {
if (val !== '' && ref.options.length > 0) {
ref.setOptionIndex(-1);
ref.moveOptionSelection(1, true);
}
},
);
}
lastVal.value = val;
}