This is a migrated thread and some comments may be shown as answers.
RadNumericTextBox default behavior issue
5 Answers 126 Views
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Albert Shenker asked on 04 Mar 2010, 05:05 PM
I notice, that if you set min/max values on a RadNumericTextBox, and a user enters a value outside of the allowable range, that the text box value gets set to the min or max, depending on which side of the range the disallowed value was entered as. For instance, if the max is set to 5.5, and the user enters 6, the value of the box gets set to 5.5. I realize that there is a brief "alert" display, but this may not be noticed. I can see how this behavior might make sense in some scenarios, however, it can also be misleading, and I'm not sure it should be the default behavior. The user might not notice that the box reset to an approporiate value and may not realize what they wanted to enter was not allowed. Since precision is often key when using numeric text boxes to enter numbers, I don't think the text box should ever "assume" what an appropriate value should be if what the user entered is invalid. Rather, it should simply not allow the user to enter the value. This is the case if the user attempts to enter an invalid character. The same should be true as far as range validation. It might be nice if Telerik has some way of alerting the user that the value they entered was greater than the max or less than the min, however, i don't have a problem with it being incumbent upon us developers to display min/max values next to the textbox. Either way, when the box gets "set" to a value the user never entered, problems can occur.

I also noticed one other small issue. If a NumericTextBox is set to allow negatives (ie the min is not set to 0), and it is also set to allow rounding, and it is also set to KeepNotRoundedValue=False, and it's decimal places is set to some value, like 2, then the following can occur.

If the value entered is negative, however, when rounded, is actually "0.00", then the numeric textbox displays -0.00.

So, in my example, if the value entered was -.004. this would round to 0.00, so the display should be "0.00". However, instead, "-0.00" is displayed and -0 is not a number. If you click on the textbox, the minus sign disppears, but this shouldn't be necessary.

5 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 05 Mar 2010, 08:25 AM
Hello Albert,

Please set

<telerik:RadNumericTextBox  AllowOutOfRangeAutoCorrect="false" />

I can't seem to reproduce the minus sign problem, what is the exact control declaration?

<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
    <NumberFormat AllowRounding="true" KeepNotRoundedValue="false" />
</telerik:RadNumericTextBox>


Sincerely yours,
Dimo
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Albert Shenker
Top achievements
Rank 1
answered on 05 Mar 2010, 04:50 PM
<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">  
    <NumberFormat AllowRounding="true" KeepNotRoundedValue="false" DecimalPlaces="2"/>  
</telerik:RadNumericTextBox> 

if you set the box value to -.004 through code, this is obviously rounded to "0.00", but the minus sign remains unless you then click on the box.
0
Dimo
Telerik team
answered on 09 Mar 2010, 04:20 PM
Hi Albert,

I see. We will fix that, thank you. Your Telerik points have been updated.

Kind regards,
Dimo
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Eduardo Dulanto
Top achievements
Rank 1
answered on 14 Feb 2011, 11:55 PM
Dear Dimo,  I have an urgent need. In our GUI we have a RadNumericTextbox for Invoice Amount currently configure by default to accept negative values with the restrivtion that the user must enter the "minus sign" first, followed by numbers.  Our business users have requested an immediate change by wich the program should preserve the default behavior and add to it the ability type in a number followed by the "minus sign". They do that in Excel and in their desk calculators. So for example a user can type 234- and the texbox will display -234.

I can not implement that,  I do not know how.  Today I tried to write a JS function to do it but it conflicts with the control's internal validations.  I also looked carefully in the documentation with out luck.  I presume that the JS function may not be necessary if one of the control's properties can be configured to do the job.

I was hoping that you can help me by indicating how to configure the properties that I need to change to achieve the desired result. 
I thank you in advance.

Eduardo.

<

 

 

telerik:RadNumericTextBox runat="server" ID="NumericField" style="width:155px;height:22px;border: 1px solid #80A0C0;font-family:Arial;font-size:10pt;padding:2px;color:Black;" IncrementSettings-InterceptArrowKeys="false" IncrementSettings-InterceptMouseWheel="false"><ClientEvents OnKeyPress="validateNumbers" /></telerik:RadNumericTextBox>

<script type="text/javascript">
    function validateNumbers(sender, eventArgs) {
        var c = eventArgs.get_keyCode();
        var keyChar = eventArgs.get_keyCharacter();
        if (c == 13) {
            eventArgs.set_cancel(true);
            return false;
        }
        if (keyChar != null) {
            if (c != 47 && c > 44 && c < 58) {
                obj = eventArgs.get_domEvent();
                var obk = obj.target.value;
                var txt = '';
                if (window.getSelection) {
                    txt = window.getSelection();
                }
                else if (document.getSelection) {
                    txt = document.getSelection();
                }
                else if (document.selection) {
                    txt = document.selection.createRange();
                }
                var textBox = document.getElementById(obj.target.id);
                if (textBox != null) {
                    //Process minus sign:
                    if (keyChar == '-') {
                        if (txt.text.toString() != "") {
                            textBox.value = "-";
                            //eventArgs.set_cancel(false);
                        }
                        else if (/-/.test(obk)) {
                            eventArgs.set_cancel(true);
                        }
                        else {
                            textBox.value = '-' + (obk.length > 0 ? obk : '');
                        }
                    }
                    //Process decimal point:
                    else if (keyChar == ".") {
                        if (txt.text.toString() != "") {
                            textBox.value = ".0";
                        }
                        else if (/\./.test(obk)) {
                            eventArgs.set_cancel(true);
                        }
                        else {
                            textBox.value = (obk.length > 0 ? obk : '') + ".";
                        }
                    }
                    else {
                        if (txt.text.toString() != "") {
                            eventArgs.set_cancel(false);
                        }
                        else {
                            textBox.value = (obk.length > 0 ? obk : '') + keyChar;
                            eventArgs.set_cancel(true);
                        }
                    }
                }
            }
        }
        }
</script>

0
Daniel
Telerik team
answered on 18 Feb 2011, 10:55 AM
Hello Eduardo,

Please try the following approach:
<script type="text/javascript">
    function numericKeyDown(sender, ev)
    {
        ev = ev || window.event;
        var keyCode = ev.keyCode || ev.charCode;
        if (keyCode == 109 || keyCode == 189)
        {
            if (sender.value[0] != '-')
                sender.value = "-" + sender.value;
            ev.cancelBubble = true;
            ev.returnValue = false;
            if (ev.preventDefault) ev.preventDefault();
            if (ev.stopPropagation) ev.stopPropagation();
        }
    }
</script>
<telerik:RadNumericTextBox runat="server" ID="NumericField" onkeydown="numericKeyDown(this, event)"
    Style="width: 155px; height: 22px; border: 1px solid #80A0C0; font-family: Arial;
    font-size: 10pt; padding: 2px; color: Black;" IncrementSettings-InterceptArrowKeys="false"
    IncrementSettings-InterceptMouseWheel="false">
</telerik:RadNumericTextBox>

I hope it is suitable for your scenario.

Regards,
Daniel
the Telerik team
Tags
Input
Asked by
Albert Shenker
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Albert Shenker
Top achievements
Rank 1
Eduardo Dulanto
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or