[select2 4.0.0-beta3] Display a link to add a new item if no results are found
See original GitHub issueIn previous versions, the formatNoMatches option could be used to provide a link to add a new item if no matches were found:
formatNoMatches: function(term) {
return "<a href='add_item?term="+term+"' class='new_item'>Add New Item</a>";
}
However when trying to replicate this using 4.0-beta3’s new languages.noResults function:
language: {
noResults: function() {
return "<a href='some_URL' class='new_item'>Add New Item</a>";
}
}
the raw unformatted string appears in the dropdown, rather than a link. Manually creating a DOM object in the function and returning that also doesn’t work, though I wouldn’t really expect it to. Is there another way to achieve this functionality in 4.0? Thanks.
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Select2: how to add a link instead of "No results found" text?
If you're using version 4 or newer of select2, try this: $('#cow_id_2').select2({ allowClear: true, escapeMarkup: function (markup) { return ...
Read more >Add, select, or clear items | Select2 - The jQuery replacement ...
The fourth parameter sets the options actual selected state - if set to true , the new option will be selected by default....
Read more >Common problems - The jQuery replacement for select boxes
Common problems. Select2 does not function properly when I use it inside a Bootstrap modal. This issue occurs because Bootstrap modals tend to...
Read more >Get searchbox values in case of not found any value in select 2
I want to add the not found data in the list of select box options. So for that i want to get he...
Read more >Retrieving selections | Select2 - The jQuery replacement for ...
Selected items can also be accessed via the :selected jQuery selector: ... Select2 does not add the selected attribute when an element is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JayatiTehri use language->noResults and escapeMarkup options to customice the no result text. 😉
@icrm-amusienko this is how i showing term