I have some code used to build a multiple select form with Select2.
$("#city-select").select2({
placeholder: "Search for a repository",
minimumInputLength: 2,
multiple: true,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "/ajax/citySelect",
type: 'post',
dataType: 'json',
quietMillis: 250,
data: function (term, page) {
return {
q: term, // search term
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter the remote JSON data
return { results: data };
},
cache: true
},
dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
});
I need to add in a few "tags" progromatically if certain events are triggered. These tags cannot be added during the initialization of the select2 form. I have not been able to find this going through their documentation and other stackoverflow questions.
Aucun commentaire:
Enregistrer un commentaire