How can I allow only integers in a NumericTextBox?
I've tried the following and it didn't work:
<
input
data-role
=
"numerictextbox"
data-format
=
"0"
data-decimal
=
"0"
data-min
=
"0"
>
Appreciate your assistance.
Best regards
Bilal Haidar
1 Answer, 1 is accepted
It seems that you've missed the "s" in the decimals option. For example:
<
input
data-role
=
"numerictextbox"
data-format
=
"0"
data-decimal
s
=
"0"
data-min
=
"0"
>
Regards,
Alexander Popov
Telerik
Thanks
Setting the decimals option to zero prevents the user from entering a decimal separator. Setting it to anything other than zero allows separator, but it also controls how many digits there might be after it in the widget's value.
Regards,
Alexander Popov
Telerik
As an FYI, when I do the above I get jquery errors (.toLowerCase) when I tried to change any values by spinning or direct typing. So I keep my input bare bones (no data attributes) and added the decimals attribute to the javascript constructor instead. This seems to have worked.
eg
<
input
type
=
'number'
class
=
'nudExecutionOrder'
/>
and
$(".nudExecutionOrder").kendoNumericTextBox({
format: "0",
decimals: 0,
min: 0,
change: onExecutionOrderChanged,
spin: onExecutionOrderChanged
});
The erroneous behavior is caused by the numeric-like format. If you would like to define such format, please use the other support syntax - {0:format} :
http://dojo.telerik.com/EdijU
Regards,
Georgi Krustev
Telerik by Progress
Thanks Georgi, but when I create an input mimicking Alexanders, eg:
<
input
data-role
=
'numerictextbox'
data-format
=
'0'
data-decimals
=
'0'
data-min
=
'0'
class
=
'nudExecutionOrder'
value
=
'5'
title
=
'...'
/>
I get the attached error of "e.toLowerCase is not a function". Perhaps this is a bug in your codebase, perhaps changing the data-format from ='0' to something else works, I never tried. I just removed all the data attributes and did it via the initialization code. Once I saw that was working I moved on to other things. Give it a shot yourself and you'll see what I mean, version of Kendo I'm using is in the screenshot.
As I mentioned in my previous reply, setting a string property (format in this case) to number would not work. The Kendo UI data-* parse mechanism will recognize "0" value as a number will treat it like that.
The proper way to overcome the described behavior is to define the string property to something that does not look like a number. That is why I suggested usage of "{0:format}" string value.
Of course initializing the widget using JavaScript is absolutely fine and if it usable to you just go for it.
Regards,
Georgi Krustev
Telerik by Progress