I have a django autocomplete light, with more than 200 options. Therefore, i want to include a button "select all".
I almost managed to do so, with the following code.
$('#facility-types').val(['2', '5', '6', '10', '11', '12', '13', '14']);
$('#facility-types').trigger('change'); // Notify any JS components that the value changed
The problem is, that with django autocomplete light, the option-tags for the select fields are only then created, when the user has manually selected an option. Furthermore, the option-tag has a data-select-2-id that appears me to be kind of random.
<option value="12" data-select2-id="127">xxxx</option>
Any ideas, how to programatically select all options of a django-autocomplete-light select field?
I have found a great solution here: https://stackoverflow.com/a/65521385/15857447
Basically you should create the option using as id the instance
pkand as name the instance__str__.There is no problem if creating this option is redundant (it already exists in the dropdown).