EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: galcott on March 19, 2023, 07:43:01 AM



Title: Filter function on numberbox
Post by: galcott 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.




Title: Re: Filter function on numberbox
Post by: jarry 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.