EasyUI Forum
October 13, 2024, 06:45:47 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: Filter function on numberbox  (Read 1711 times)
galcott
Newbie
*
Posts: 42


View Profile
« on: March 19, 2023, 07:43:01 AM »

Please refer to this discussion in which I asked how to disable the decimal point in a numberbox.
https://www.jeasyui.com/forum/index.php?topic=8479.0

I just discovered that on numberboxes where I use the code you provided, the getValue method no longer works when the value is changed.. Even after the change, getValue still returns the old value. I have to use getText instead.

Can you explain the difference between getValue and getText for numberboxes? They always seem to return the same thing so I don't understand why getValue even exists.


Logged
jarry
Administrator
Hero Member
*****
Posts: 2275


View Profile Email
« Reply #1 on: March 20, 2023, 07:03:45 PM »

Please look at this example. The 'getValue' method works fine.
Code:
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Basic NumberBox - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script>
$(function () {
$('#nb').numberbox({
precision: 0,
filter: function (e) {
if (String.fromCharCode(e.which) == '.') {
return false;
} else {
return $.fn.numberbox.defaults.filter.call(this, e);
}
}
})
})
</script>
</head>

<body>
<input id="nb" label="NumberBox1:" labelPosition="top">
<button class="easyui-linkbutton" onclick="alert($('#nb').numberbox('getValue'))">GetValue</button>
</body>

</html>

The 'getValue' method returns the value while the 'getText' method returns the displaying text. They are different in some conditions. For example, if you set the 'prefix' property or some other formats, the 'getText' method will return the formatted text that looks like '$23.24', but the 'getValue' method only returns the '23.24' value according to the 'precision' setting.
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!