Skip to content

Commit

Permalink
remove already assigned tags from autocomplete suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Rehfeld committed May 20, 2010
1 parent fcdfbb6 commit cb97a10
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion js/tag-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@
});

tag_input.autocomplete({
source: options.availableTags,
source: function(req, show_choices){
show_choices(subtract_array(options.availableTags,assigned_tags()));
},
select: function(event,ui){
if (is_new (ui.item.value)) {
create_choice (ui.item.value);
Expand All @@ -100,6 +102,24 @@
}
});

function assigned_tags(){
var tags = [];
this.tag_input.parents("ul").children(".tagit-choice").each(function(){
tags.push($(this).children("input").val());
});
return tags;
}

function subtract_array(a1,a2){
var result = new Array();
for(var i in a1) {
if (a2.indexOf(a1[i]) == -1) {
result.push(a1[i]);
}
}
return result;
}

function is_new (value){
var is_new = true;
this.tag_input.parents("ul").children(".tagit-choice").each(function(i){
Expand Down

0 comments on commit cb97a10

Please sign in to comment.