javascript - Bootstrap chosen add new item if no exist -


i trying add new item if not exist. code working dont know how add item directly on list of selected.

chosen.prototype.no_results = function(terms) {   var no_results_html;   no_results_html = $('<li class="no-results">' + this.results_none_found + '"<span></span>" kao' +     ' <button class="add" id="interni" class="submit"> interni tip </button> ' +     ' <button class="add" id="eksterni" class="submit"> eksterni tip</button> ' +     '</li> ');   no_results_html.find("span").first().html(terms);   no_results_html.find(".add").click(function() {      var terms1 = terms + ' (' + this.id + ')';      $('.chosen-select').chosen().append('<option>' + terms1 + '</option>');     $('.chosen-select').chosen().trigger('chosen:updated');    });   return this.search_results.html(no_results_html); }; 

resolved: add selected atribute on option tag.

 $('.chosen-select').chosen().append('<option selected>' + terms1 + '</option>'); 


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -