Prevent adding a duplicate to a multiselect
This commit is contained in:
parent
05cb94801a
commit
8e4832bd12
|
@ -129,13 +129,24 @@
|
||||||
if(event.keyCode == 13) {
|
if(event.keyCode == 13) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
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();
|
var li=$(this).parent();
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
li.text('+ '+settings.createText);
|
li.text('+ '+settings.createText);
|
||||||
li.before(createItem(this));
|
li.before(createItem(this));
|
||||||
var select=button.parent().next();
|
var select=button.parent().next();
|
||||||
var option=$('<option selected="selected"/>');
|
var option=$('<option selected="selected"/>');
|
||||||
option.attr('value',$(this).val());
|
option.attr('value',value);
|
||||||
option.text($(this).val());
|
option.text($(this).val());
|
||||||
select.append(option);
|
select.append(option);
|
||||||
li.prev().children('input').trigger('click');
|
li.prev().children('input').trigger('click');
|
||||||
|
|
Loading…
Reference in New Issue