Can I use it with Svelte? #161
Replies: 2 comments 2 replies
-
As stated on the main repo page, it's framework agnostic. p.s: As of now this is the first google result for: "tom-select svelte" query, hence why I bump this discussion. |
Beta Was this translation helpful? Give feedback.
-
Just thought I'd expand on this: yes, you can use it with Svelte, but with some modifications. TomSelect expects to modify the DOM directly; when the Svelte compiler runs, the document doesn't really exist yet, so you'll get lots of rather frustrating errors. I adapted a technique I'd previously used with another component script; here's how I use tom-select: <script lang="ts">
import TomSelect from "tom-select";
import 'tom-select/dist/esm/plugins/remove_button/plugin';
import 'tom-select/dist/css/tom-select.css';
// import your custom stylesheet here
let stateSelect;
onMount(async () => {
stateSelect= new TomSelect("#select-state",{
// your settings go here
});
});
</script>
<select id="select-state" name="state[]" multiple placeholder="Select a state..." autocomplete="off">
<option value="">Select a state...</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="CA" selected>California</option>
</select> This feels weird to me - we don't do anything with |
Beta Was this translation helpful? Give feedback.
-
Is there a way I can use it with Svelte?
Beta Was this translation helpful? Give feedback.
All reactions