- How do I catch the user input and pass it to the create text field.
Current code shows 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 })
});