You ask you want to submit, something different. Then lets take that single point of entry:
$('#data').submit(function() {
// Change the value we are submitting
var tagids = [];
$.each($('#singleFieldTags').val().split(','),
function(idx, taglabel){
tagids.push(lookup_tagid_for_label(taglabel));
}
)
$('#singleFieldTags').val(tagids.join(','));
return true; // Let the event go on.
});
That should change the labels with the ids before submit.
lookup_tagid_for_label
, could either do the ajax call again, but it may be cheaper to cache it on the field at first lookup:
$("#singleFieldTags").tagit({
autocomplete: {
source: function(search, showChoices) {
$.getJSON("/repo/json", {q: search.term},
function (data) {
var choices = [];
$.each(data, function (idx, tag) {
choices.push(tag.name);
$("#singleFieldTags").data(tag.name, tag.id);
});
showChoices(choices);
});
}
});
Then you can replace lookup_tagid_for_label(taglabel)
with $("#singleFieldTags").data(taglabel)
.
In contrary to my other answer, that expected tag-it to follow the autocomplete-api, this works now.