Replies: 4 comments 1 reply
-
That is one of the solutions. Tom Select needs an option to exist for the value set in The other approach is the set the default selected option (using the setValue() method) right after the options are loaded dynamically. |
Beta Was this translation helpful? Give feedback.
-
For anyone else looking for a way to set the default values from a remote source, here's my solution, it's quite easy actually: #240 (comment) |
Beta Was this translation helpful? Give feedback.
-
When you initialize the control right before you edit the data, provide two arrays for the options and the items parameters. For example, load from the database your selected options: eg.
and then you have to tell the control to select the options:
Make sure you have the following correct when you initialize the control:
This is an example from my test app editing a record. I have 2 select boxes. On the second I select the options and on the first (tomselect) I add the selected values. I did it so in order to see how I can pass the values to tomselect and it worked.: |
Beta Was this translation helpful? Give feedback.
-
✅ Best working solution
this is how we can do this, only pass default ids and tomSelect will handle the rest. all action after this is working correctly. |
Beta Was this translation helpful? Give feedback.
-
I'm loading options from a remote source, like this example: https://tom-select.js.org/examples/remote/
It's working fine, however, I'm not able to set a default selected option.
I tried to add the
items: [1]
option, both with the value as the name of the option that should be selected (items['Amsterdam']
). But that only works when I add static options instead of from a remote source. I also tried to preload the data.Is there a solution for this?
Beta Was this translation helpful? Give feedback.
All reactions