EasyUI Forum
March 04, 2024, 01:19:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Validate numberbox  (Read 745 times)
galcott
Newbie
*
Posts: 39


View Profile
« on: February 20, 2023, 09:00:35 AM »

I have some numberboxes where I don't want to allow them to be blank. If the user erases the field, I want to enter "0.00", and I want this to happen on the blur event without any message displaying. This will only apply to numberboxes containing a specific class name. I can't figure out how to use validation to do this. Please give me some sample code for this purpose. Thanks.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2260


View Profile Email
« Reply #1 on: February 21, 2023, 01:23:59 AM »

Please override the 'blur' handler for the numberbox.
Code:
$.extend($.fn.numberbox.defaults.inputEvents, {
blur: function(e){
var t = $(e.data.target);
if (t.hasClass('f1') && !$.trim(t.numberbox('getText'))){
t.numberbox('setValue',0);
} else {
t.numberbox('fix');
}
}
})

If the numberbox component has the 'f1' class, it will auto fill the '0.00' value by default.
Code:
<input class="easyui-numberbox f1" label="List Price:" labelPosition="top" precision="2" value="234.56" style="width:100%;">
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!