Also I need to use "tags" in select2 which Allows values that are not in the list(Ajax result).
Both the scenarios work independently. But joined together aJax values are only populated. If we type any other values not in the list then it says "no matches found"
My scenario If user type any new value which is not in the list, allow them to make up their own tag.
Any way to make this work?
回答1:
Select2 has the function "createSearchChoice":
Creates a new selectable choice from user's search term. Allows creation of choices not available via the query function. Useful when the user can create choices on the fly, eg for the 'tagging' usecase.
Here's a more complete answer that returns a JSON result to an ajax search, and allows tags to be created from the term, if the term returned no results:
You can make this work, by having your ajax function also return the search term, as the first result in the result list. The user can then select that result as a tag.