Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Simple Developer
Simple Developer
If you want to give user can add new options to select tag in runtime, you can use Select2 jQuery library to do it.
Final result is like this:
$('select').select2({
tags: true
});
createTag
function to add extra properties$('select').select2({
tags: true,
createTag: function (params) {
var term = $.trim(params.term);
if (term === '') {
return null;
}
return {
id: term,
text: term,
newTag: true // add additional perameters
}
}
});
templateResult
function to display “(new)” text inside of item$('select').select2({
tags: true,
createTag: function (params) {
var term = $.trim(params.term);
if (term === '') {
return null;
}
return {
id: term,
text: term,
newTag: true // add additional perameters
}
},
templateResult: function(data) {
var $result = $("");
$result.text(data.text);
if (data.newTag) {
$result.append(" (new)");
}
return $result;
}
});