EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: kingor2001 on June 22, 2019, 09:07:51 PM



Title: How to prevent tagbox from accepting invalid tag?
Post by: kingor2001 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());
   }
});


Title: Re: How to prevent tagbox from accepting invalid tag?
Post by: stworthy 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);
}
}
})
})