I have a Select2 control working with AJAX - I can search a remote repository and select options from it just fine. What I want to do though is add a new option to the control every time the AJAX search comes back to add that search term as a new option.
It shouldn't just add it when the search comes back empty, but with every search.
Ex: I search for baseball
and my AJAX search returns the following results:
baseball fields
baseball games
baseball equipment
I want the Select2 dropdown to display:
baseball fields
baseball games
baseball equipment
baseball (Add As New)
Hoping this is as easy as just finding the correct Select2 option to hook into. I can easily append an option in the processResults
section of the ajax
option, but can't figure out how to grab the actual term that was searched for.
EDIT: This problem is solvable in versions 3.5.2 and below, but I'm using 4.0.