EasyUI Forum
June 19, 2024, 04:31:39 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to prevent a tagbox from accepting duplicate values?  (Read 2627 times)
kingor2001
Jr. Member
**
Posts: 61


View Profile
« 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.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2266


View Profile Email
« Reply #1 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.'
}
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!