Prevent adding a duplicate to a multiselect

This commit is contained in:
Michael Gapczynski 2012-06-29 16:44:08 -04:00
parent 949cab7ea1
commit dd7d34a40e
1 changed files with 12 additions and 1 deletions

View File

@ -129,13 +129,24 @@
if(event.keyCode == 13) {
event.preventDefault();
event.stopPropagation();
var value = $(this).val();
var exists = false;
$.each(options,function(index, item) {
if ($(item).val() == value) {
exists = true;
return false;
}
});
if (exists) {
return false;
}
var li=$(this).parent();
$(this).remove();
li.text('+ '+settings.createText);
li.before(createItem(this));
var select=button.parent().next();
var option=$('<option selected="selected"/>');
option.attr('value',$(this).val());
option.attr('value',value);
option.text($(this).val());
select.append(option);
li.prev().children('input').trigger('click');