Skip to content

Commit

Permalink
MultiSelect fix form validation reset when required prop changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Apr 8, 2024
1 parent 8cf89b0 commit 865c178
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@
// create Highlight object from ranges and add to registry
CSS.highlights.set(`sms-search-matches`, new Highlight(...ranges.flat()))
}
// reset form validation when required prop changes
// https://github.com/janosh/svelte-multiselect/issues/285
$: required, form_input?.setCustomValidity(``)
</script>

<svelte:window
Expand All @@ -485,7 +489,7 @@
<!-- bind:value={selected} prevents form submission if required prop is true and no options are selected -->
<input
{name}
required={Boolean(required)}
{required}
value={selected.length >= Number(required) ? JSON.stringify(selected) : null}
tabindex="-1"
aria-hidden="true"
Expand Down

0 comments on commit 865c178

Please sign in to comment.