EasyUI Forum
April 18, 2024, 02:19:05 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: Filter function on numberbox  (Read 4374 times)
galcott
Newbie
*
Posts: 39


View Profile
« on: June 23, 2021, 10:46:08 AM »

When using numberboxes, sometimes I want to allow a decimal point and other times not to allow it. I can't figure out how to do this. I see there is a filter property that takes a function, but absolutely no information on how to use it. Can you provide an example of a filter function, or another way to specify whether to allow a decimal? This is missing from the documentation. Thank you.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: June 25, 2021, 02:34:20 AM »

The 'precision' property can be defined to specify the precision to display after the decimal separator. If you doesn't allow it, set the 'precision' to 0.

Code:
$('#nb').numberbox({precision:2})
Logged
galcott
Newbie
*
Posts: 39


View Profile
« Reply #2 on: June 25, 2021, 06:27:19 AM »

Even if you set precision to 0, it still allows the decimal point. I don't want to allow it at all. I'm using it to enter fields like Zip code and credit card number.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: June 25, 2021, 07:12:19 AM »

The decimal point will be removed and the value will be fixed after the user press ENTER key or the inputing box loses focus. If you want to disable the decimal point absolutely, custom the 'filter' function to prevent from entering it.
Code:
$('#nb').numberbox({
precision: 0,
filter: function(e){
if (String.fromCharCode(e.which) == '.'){
return false;
} else {
return $.fn.numberbox.defaults.filter.call(this, e);
}
}
})
Logged
galcott
Newbie
*
Posts: 39


View Profile
« Reply #4 on: June 25, 2021, 07:28:19 AM »

This is what I was looking for. That sample code should be in the documentation, since it doesn't currently include any explanation of how to use the filter function.
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!