EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: kingor2001 on June 21, 2019, 08:20:12 AM



Title: How to prevent a tagbox from accepting duplicate values?
Post by: kingor2001 on June 21, 2019, 08:20:12 AM
How to prevent a tagbox from accepting duplicate value?
I can input some duplicate values in a tagbox now, but sometimes I want the tagbox prevent from adding a new value which existing in tagbox's values.


Title: Re: How to prevent a tagbox from accepting duplicate values?
Post by: jarry on June 22, 2019, 06:56:07 AM
Define a validation rule and apply it to the tagbox.
Code:
$.extend($.fn.validatebox.defaults.rules, {
duplicatetag: {
validator: function(value,param){
value = $.trim(value).replace(/\,$/,'');
var vv = value.split(',');
if((new Set(vv)).size != vv.length){
return false;
}
return true;
},
message: 'Duplicate tags.'
}
})