django-formset
                                
                                
                                
                                    django-formset copied to clipboard
                            
                            
                            
                        Selectize programmatic value selection.
Is it possible to programmatically select and set a value in the Selectize field?
I have a form with Selectize field. I added a button near this field. When I press this button I call the form for adding a new item to a base table, which is set as foreign_key in the Selectize field. The form is called modally. After closing the form, the new element is added to the base and I would like to set this element as selected in the Selectize field.
Could you please advise me the way to solve the problem?
In version 1.4 there is full support for dialog forms. There the use-case you're describing is not handled but it seems interesting enough to be implemented.
I will implement this soon. Have been busy with releasing version 1.4.
wow :) Great! thank you!
In version 1.4 the Selectize web component offers a getter and setter function for value. Please try them out.
Great! I'll try it tonight. Thank you very much! you're the best! :)
is there any documentations how to use setters/getters?
Just find the original HTMLSelectElement in the DOM using querySelector or getElementById.
Then you can just set and get its value. Internally this then is retrieved/applied to the TomSelect component, which is doing the heavy lifting.
I see. Ok. Thank you.
I've just had a chance to test this. It works fine when all list of selected values are uploaded to a browser. If I added new item in the backend and set the value of select in frontend it doesn't work. Could you make update selected options?
I'm glad that you ask.
This feature has been implemented in version 1.5 – you may have a look at the develop-branch. There are still some issues in 1.5, hence I havn't released it yet.