EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: galcott on February 20, 2023, 09:00:35 AM



Title: Validate numberbox
Post by: galcott 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.


Title: Re: Validate numberbox
Post by: jarry 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%;">