EasyUI Forum
June 19, 2024, 05:05:34 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 tagbox from accepting invalid tag?  (Read 2596 times)
kingor2001
Jr. Member
**
Posts: 61


View Profile
« on: June 22, 2019, 09:07:51 PM »

How to prevent tagbox from accepting invalid tag?
for example,
I want a tag's maxlength is 5, but the user input a tag such as 'easyui' which including 6 chars. I hope that tagbox NO ADD 'easyui' into values as a tag instead of showing a invalidMessage after added.
Now I deal as follow,
tagbox.textbox('textbox').bind('keydown', function(e){
   if (e.keyCode == 13){   
      tagbox.textbox('setValue', $(this).val().length>5?'':$(this).val());
   }
});
« Last Edit: June 22, 2019, 09:55:36 PM by kingor2001 » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: June 24, 2019, 07:14:18 AM »

Please override the 'enter' handler to custom your tag logic.
Code:
$('#tb').tagbox({
keyHandler: $.extend({}, $.fn.tagbox.defaults.keyHandler, {
enter: function(e){
var t = $(this);
var v = $.trim($(this).tagbox('getText'));
if (v !== '' && v.length<6){
var values = $(this).tagbox('getValues');
values.push(v);
$(this).tagbox('setValues', values);
}
}
})
})
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!