select2 noresult catch the input

42 views
Skip to first unread message

kent...@gmail.com

unread,
Sep 24, 2015, 2:09:12 AM9/24/15
to select2
http://stackoverflow.com/questions/32652983/select2-noresult-catch-the-input

How do I catch the user input and passed to the create text field.
Current code shows that undefined.

And the new term also not added to the list, the alert seem like not working.

$.getScript('//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.js',function(){

$("#mySel").select2({ width:'240px', allowClear:true, "language": { "noResults": function(term) { /* customize the no matches output */ return "Create" } },

escapeMarkup: function (markup) {
return markup;
}
}) .parent().find('.select2-with-searchbox').on('click','#addNew',function(){ /* add the new term */ var newTerm = $('#newTerm').val(); alert('adding:'+newTerm); $(''+newTerm+'').appendTo('#mySel'); $('#mySel').select2('val',newTerm); // select the new term $("#mySel").select2('close'); // close the dropdown })

});

http://www.codeply.com/go/LxasHWd0rd

Reply all
Reply to author
Forward
0 new messages