EasyUI Forum
April 26, 2024, 12:02:27 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: Datebox accepts alphabetic characters, which it shouldn't  (Read 1615 times)
galcott
Newbie
*
Posts: 39


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


View Profile Email
« Reply #1 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;
}
}
})
})
Logged
galcott
Newbie
*
Posts: 39


View Profile
« Reply #2 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.
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!