twitter bootstrap - Load and Edit Remote Data with Select2() 4.0 -


i have problem pluging select2() v4.0. want load remote data in mi modal boostrap , edit values. code is:

html

 <select id="txtasistentes" class="js-example-basic-multiple" multiple="multiple" style="width: 100%" /> 

js

controltoselect2format: function (controlid,ocultos) {     var control = "#" + controlid;     $(control).select2({                   minimuminputlength: 2,  // minimuminputlength sending ajax request server         width: 'resolve',   // adjust proper width of select2 wrapped elements          tags: false,         allowclear: false,         multiple: true,         ajax: {             url: "/home/searchuserad/",             datatype: 'jsonp',             data: function (params) {                 return {                     term: params.term, // search term                     page: params.page                 };             },             processresults: function (data, page) {                                  return { results: data.results };             }         },                   initselection: function (element, callback) {             var id = $("#hdreservaid").val();             if (id !== "") {                 $.ajax({                     url: "/home/getasistentesreserva/",                     datatype: "jsonp",                     data: { idreserva: id }                                        }).done(function (data) {                      callback(data.results);                 })             }         }     }); } 

the initselection ok, because use "select2.full.min.js" problem when try edit values initselection precharge select2 control. lose values , clear control.

how can edit initial values without remove values?

my problem when want editing data created , saved before. don't know how editing select2()

thanks!

finally solution have been put code after of select() initialization, , remove code initselection:

    var id = $("#hdreservaid").val();     if (id !== "") {         $.ajax({             url: "/home/getasistentesreserva/",             datatype: "jsonp",             data: { idreserva: id }         }).then(function (data) {             data.results.foreach(function (entry) {                 //alert(entry);                 var $option = $('<option selected>' + entry.text + '</option>').val(entry.id);                 $(control).append($option).trigger('change');             });             $(control).trigger('change');         });     } 

if modal opened editing, call ajax editing data. method can editing without problem data select2() multiselect .

thank support!!


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -