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

RadNumericTextbox clear value when outside of range

3 Answers 211 Views
Input
This is a migrated thread and some comments may be shown as answers.
License
Top achievements
Rank 1
License asked on 05 Mar 2014, 02:21 PM
How can I go about clearing the textbox when an entered value exceeds the min or max value instead of setting the value to the min or max?

3 Answers, 1 is accepted

Sort by
0
License
Top achievements
Rank 1
answered on 05 Mar 2014, 02:24 PM
Just little more info...

I am setting the limitations programmatically, so I can't really hard-code some values into a client-side function and check against that. I can't really tell what Client Events occur when the input is not within the range, but I would imagine that's the approach I would need to take here.
0
Princy
Top achievements
Rank 2
answered on 06 Mar 2014, 05:59 AM
Hi Robert,

One Suggestion is that you can programmatically find a range for RadNumericTextBox and assign those values in HiddenField, then compare those values with the RadNumericTextBox value in OnValueChanged event. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" ClientEvents-                           OnValueChanged="OnValueChanged">
</telerik:RadNumericTextBox>
<asp:HiddenField ID="MinValue" runat="server" />
<asp:HiddenField ID="MaxValue" runat="server" />

JavaScript:
<script type="text/javascript">
    function OnValueChanged(sender, args) {
        //programatically set a maximum value and minimum value to the hidden fields
        var max = document.getElementById("MaxValue").value;
        var min = document.getElementById("MinValue").value;
        if (args.get_newValue() < min && args.get_newValue() > max)
            sender.set_value("");
    }
</script>

Let me know if you have any concern.
Thanks,
Princy.
0
Vasil
Telerik team
answered on 06 Mar 2014, 01:18 PM
Hello Robert,

You can also set AllowOutOfRangeAutoCorrect="true" as alternative. In this case the input will be shown as invalid without auto-correcting the value.

Regards,
Vasil
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Tags
Input
Asked by
License
Top achievements
Rank 1
Answers by
License
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or