nl...@corp.oodle.com
unread,Aug 4, 2015, 12:21:44 PM8/4/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to select2
Hello! I’m working on a project using select2 v4 tagging support.
<select id="tags" name="tags[]" />
I hope to have a few prefilled tags, then have the user be able to select from remote values as well as enter new ones. I got the tagging to work with pre filled values:
var app_tags=['red', 'green'];
$('select#tags').select2({
tags: app_tags,
multiple: true,
tokenSeparators: [',']
});
$("select#tags").select2('val', app_tags);
Then I added the ajax:
var app_tags=['red', 'green'];
$('select#tags').select2({
tags: app_tags,
multiple: true,
tokenSeparators: [‘,’],
createSearchChoice: function(term, data) {
if ($(data).filter(function() {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return {
id: term,
text: term
};
}
},
ajax: {
url: “/some/url”,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term
};
},
processResults:
function(data){
return {
results: $.map(data, function (item) {
return item;
})
};
},
cache: true
},
minimumInputLength: 2
});
$("select#tags").select2('val', app_tags);
I can now select from remote list and enter new values very well, but the prefilled tags no longer exist. How do I make them show?
Thanks!