Skip to content

Commit

Permalink
Refs #4862 - Fixed duplicate tags in edit form.
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Apr 12, 2012
1 parent 5e53797 commit ffffa8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

4.4-dev - (unreleased)
----------------------
* Bug fix: Fixed duplicate tags in edit form
[voineali #4862]

4.3 - (2011-12-15)
------------------
Expand Down
24 changes: 15 additions & 9 deletions eea/tags/browser/js/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ jQuery.fn.eeatags = function(options){
self.allowNewTokens = true;
}

self.prePopulate = [];
var existingTags = [];
var prePopulate = jQuery('select[name*=existing]', self);
if(prePopulate.length){
var selected = prePopulate.val();
jQuery.each(selected !== null ? selected : [], function(index){
var item = {id: this, name: this};
self.prePopulate.push(item);
jQuery.each(selected !== null ? selected : [], function(index, val){
if(existingTags.indexOf(val) === -1){
existingTags.push(val);
}
});
}else{
prePopulate = jQuery('input[type=checkbox]:checked', self);
jQuery.each(prePopulate, function(index){
var context = jQuery(this);
var item = {id: context.val(), name: context.val()};
self.prePopulate.push(item);
var item = context.val();
if(existingTags.indexOf(item) === -1){
existingTags.push(item);
}
});
}

Expand All @@ -41,13 +44,16 @@ jQuery.fn.eeatags = function(options){
prePopulate = prePopulate.val().split('\n');
jQuery.each(prePopulate, function(index){
var val = this.trim();
if(val){
var item = {id: val, name: val};
self.prePopulate.push(item);
if(val && existingTags.indexOf(val) === -1){
existingTags.push(val);
}
});
}

self.prePopulate = jQuery.map(existingTags, function(val, idx){
return {id: val, name: val};
});

self.tags = [];
var tags = jQuery('select[name*=existing]', self);
if(tags.length){
Expand Down

0 comments on commit ffffa8c

Please sign in to comment.