maxLength - Numeric Textbox

1 Answer 2901 Views
General Discussions
Parag
Top achievements
Rank 1
Parag asked on 12 Mar 2019, 08:24 PM

Hi,

 

 I am trying to set maxLength property to NumericTextBox, but it is not working. Is it not supported?

 

example 

maxLength="5"

 

Regards,

Parag

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 13 Mar 2019, 07:45 AM
Hello, Parag,

This can be achieved using different approaches depending on the desired result.

If the length of 5 will cover only the whole number part, then the max can be set to 99999. This will prevent the user to write a bigger number:

https://www.telerik.com/kendo-react-ui/components/inputs/api/NumericTextBoxProps/#toc-max

If these 5 symbols will include the decimal part as well, I can suggest using the change event and checking the length of the value. If the value length is bigger then 5, do not set the value as show a message to the user;

https://stackblitz.com/edit/react-gcpjem?file=app/main.js

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Sadaf
Top achievements
Rank 1
commented on 25 Mar 2019, 10:51 AM

Hi Stefan,

Thank you for the response! I used the suggested approach and was able to set maxLength to the NumericTextBox.

This approach works fine if the number is a whole number. What should I do if I have to put maxLength restriction on a field with decimal values?

For example,

I have a field for which maxLength should be 5 characters and user should be able to enter maximum of 2 digits after decimal. If I put maxLength restriction on the field where I have set the format property as "#.##", the digits after decimal are removed and the value of the field is rounded off to a whole number if the max length limit is crossed.

 

Thanks,

Sadaf Patwekar

Stefan
Telerik team
commented on 26 Mar 2019, 09:19 AM

Hello, Sadaf,

If the combined length of the whole number + decimals has to be 5 I can suggest removing the decimal separator(culture-specific). This will count all numbers as one type:

https://stackblitz.com/edit/react-gcpjem?file=app/main.js

If the max length has to be only for the whole number, then remove everything after the decimal separator before making the check.

Let me know if I missed some important detail.

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Parag
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or