Trying to get tag-it to work with an ajax call.
Everything works so far. Except, I am unable to assign a tagSource via an ajax call.
In firebug, the 'data' is returning:
["Ruby","Ruby On Rails"]
But its not showing up as I type into the input box.
$('.tags ul').tagit({
itemName: 'question',
fieldName: 'tags',
removeConfirmation: true,
availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"],
allowSpaces: true,
// tagSource: ['foo', 'bar']
tagSource: function() {
$.ajax({
url: "/autocomplete_tags.json",
dataType: "json",
data: { term: 'ruby' },
success: function(data) {
console.log(data);
return data;
}
});
}
});
console.log(data)
returns ["Ruby", "Ruby On Rails"]
.
Am I missing something here? Anyone else got this to work?
You should remove your
availableTags
, as you are overloadingtagSource
, which is used as source for the autocompletion.Also that may be a typo, but it "
return
", and not "eturn
".Edit:
I think the problem is that the function you provided to
tagSource
doesn't seems to return anything. However my javascript knowledge seems to end here :/