I have a selectable field that uses the django-select2 library. I am currently trying to copy the behaviour of the "add another" functionality present in the admin forms of Django.
I added a "+" icon to my regular form template and opened a popup so that the user can register a new item. This part works, now I wish to select the newly added item automatically once the popup is closed. I cannot seem to add a new option to the selectable, though.
I read the original dismissAddAnotherPopup()
code and the select2
docs on that, but appending a new Option(...)
to the element does not have the desired effect - in fact it adds as many options as I want, but they appear under the select box instead of in the dropdown menu, as if they were completely different things.
I looked at the html result and it seems the select2
field is not using <option ...>
for the options rendered with Django, but rather some deeper nested elements for the options.
What is the correct syntax for adding new options in this situation?