Numeric Textbox Min and Max

2 posts, 0 answers
  1. Paul
    Paul avatar
    33 posts
    Member since:
    Mar 2013

    Posted 23 Apr 2015 Link to this post

    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.





  2. Daniel
    Daniel avatar
    2231 posts

    Posted 27 Apr 2015 Link to this post

    Hello Paul,

    The approach will be the same with the latest versions. Basically, you should use custom attributes different than min and max:
        .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.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top