This is a migrated thread and some comments may be shown as answers.

Numeric Textbox Min and Max

1 Answer 1061 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 23 Apr 2015, 04:04 PM

Hi there,

I am seeking to achieve the same outcome as described in this forum post - changing the default behaviour of the numeric textbox when a min and max value has been supplied. The default behaviour is

  • For a numeric textbox with min =0, max = 100
  • User mistakenly types in 500 instead of 50
  • Control automagically "corrects" this to 100 (this just seems plainly wrong) without informing the user in any way.

I had already tried to implement something similar to the solution mentioned in that forum post - however, it doesn't work (presumably because the controls have been updated since). By the time the validation rule runs, the value has already been adjusted to the maximum value, so the rule always passes.

Can you advise how I can achieve this behaviour? I am using Q3 2014.

Thanks,

 

Paul.

 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 27 Apr 2015, 01:51 PM
Hello Paul,

The approach will be the same with the latest versions. Basically, you should use custom attributes different than min and max:
@(Html.Kendo().NumericTextBox()
    .Name("MyNumber")
    .HtmlAttributes(new {data_min = 5, data_max = 10, data_val_msg = "My Special error message." })
    .Placeholder("Enter numeric value")
)
and handle the validation in the custom rule for inputs with the specific custom attribute. Besides using the HtmlAttributes method, you could also implement a custom DataAnnotation attribute and extend the validator with the custom rule so that the validation can easily be reused. 
If this approach does not work in your scenario then a possible reason is that a RangeAttribute is used on the property. The NumericTextBox helper will detect it and will set the min and max values.


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
NumericTextBox
Asked by
Paul
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or