EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: galcott on April 02, 2022, 04:01:43 PM



Title: Datebox accepts alphabetic characters, which it shouldn't
Post by: galcott on April 02, 2022, 04:01:43 PM
I have just found that the datebox component accepts alphabetic characters (a-z) which it definitely should not. Obviously it should only accept digits and date separators. I have tried to fix this by binding the keypress event to a function that checks the character typed and returns false if it's not a digit or separator but that doesn't work. How can this be fixed?


Title: Re: Datebox accepts alphabetic characters, which it shouldn't
Post by: jarry on April 03, 2022, 07:04:20 AM
The code below shows how to override the 'inputEvents' and bind the 'keypress' event on the datebox component.
Code:
$('#d1').datebox({
inputEvents: $.extend({},$.fn.datebox.defaults.inputEvents,{
keypress: function(e){
var c = String.fromCharCode(e.which);
if ('0123456789/'.indexOf(c) >= 0){
return true;
} else {
return false;
}
}
})
})


Title: Re: Datebox accepts alphabetic characters, which it shouldn't
Post by: galcott on April 03, 2022, 09:52:16 AM
That works but why isn't that the normal behavior? A datebox should only accept digits and separators. This is definitely a bug.