Skip to content

Commit

Permalink
fix: $value calculated onMount in autocomplete select (#1272)
Browse files Browse the repository at this point in the history
Co-authored-by: Abderrahmane Smimite <[email protected]>
  • Loading branch information
Mohamed-Hacene and ab-smith authored Dec 28, 2024
1 parent fb150f6 commit a373fef
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit a373fef

Please sign in to comment.