Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: $value calculated onMount in autocomplete select #1272

Merged
merged 5 commits into from
Dec 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions frontend/src/lib/components/Forms/AutocompleteSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,24 @@

const default_value = nullable ? null : selectedValues[0];

function arraysEqual(arr1: (string | undefined)[], arr2: (string | undefined)[]) {
if (arr1?.length !== arr2?.length) return false;

const set1 = new Set(arr1);
const set2 = new Set(arr2);

for (const value of set1) {
if (!set2.has(value)) return false;
}

return true;
}

$: {
$value = multiple ? selectedValues : (selectedValues[0] ?? default_value);
handleSelectChange();
if (!arraysEqual(selectedValues, $value)) {
$value = multiple ? selectedValues : (selectedValues[0] ?? default_value);
handleSelectChange();
}
}

$: disabled = selected.length && options.length === 1 && $constraints?.required;
Expand Down
Loading