RadNumericTextBox broken now when validating Currency values

9 posts, 1 answers
  1. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 18 Jun 2012 Link to this post

    Something changed re: RadNumericTextBoxes in the newest version of the Telerik Rad Ajax Controls (2012.2.607.40)

    Our client-side/markup validators are all now broken on any currency validation as the "$" and the "," values are being passed thru instead of the raw value.

    This change just happened with this new version of the Ajax controls and we have a lot of code that is now broken in production.

    Need someone at Telerik to address this ASAP.

    <telerik:RadNumericTextBox ID="rntbBudget" runat="server" CssClass="TextboxAnimated" Width="150px"
        Type="Currency" DataType="Decimal" DbValue='<%# Eval("fldBudget") %>' NumberFormat-DecimalDigits="2" />
    <asp:RequiredFieldValidator ID="rfvBudget" runat="server" ControlToValidate="rntbBudget"
        ErrorMessage="Must enter a Budget amount!" Text="!" CssClass="errorMessage" />
    <asp:CompareValidator ID="cvBudget" runat="server" ControlToValidate="rntbBudget" ValueToCompare="0.00"
        Operator="GreaterThan" Type="Currency" ErrorMessage="The Budget amount must be greater than $0.00!" Text="!" CssClass="errorMessage" />


    The above code now generates a validation error when it never did before.

    Jerry



    **EDIT**

    Below is a workaround, for now:
    <telerik:RadNumericTextBox ID="rntbBudget" runat="server" CssClass="TextboxAnimated" Width="150px"
        Type="Number" DataType="Decimal" DbValue='<%# Eval("fldBudget") %>' NumberFormat-DecimalDigits="2" NumberFormat-GroupSeparator="" />
    <asp:RequiredFieldValidator ID="rfvBudget" runat="server" ControlToValidate="rntbBudget"
        ErrorMessage="Must enter a Budget amount!" Text="!" CssClass="errorMessage" />
    <asp:CompareValidator ID="cvBudget" runat="server" ControlToValidate="rntbBudget" ValueToCompare="0.00"
        Operator="GreaterThan" Type="Currency" ErrorMessage="The Budget amount must be greater than $0.00!" Text="!" CssClass="errorMessage" />

    Notice the changes: The Type attribute on the RadNumericTextBox had to be changed from "Currency" to "Number" and the NumberFormat-GroupSeparator attributte had to be added but set to an empty string "".

    This means a LOT of our production code now needs to be modified due to this underlying change in the RadNumericTextBox control.

    Why did that change? There was no mention of it in the release notes either.
  2. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 19 Jun 2012 Link to this post

    Hello Jerry,

    Try to add the flowing script under the declaration of your script manager to see if the problem will be resolved.

    Currently the validation passes on 'onchange' event which is earlier than the onblur event on which we compute the validation value. The code below avoid making the validation on "onchange" when it is triggered by the browser. The input control internally calls "onchange" when it need, so the validation will pass correctly just a bit later.

    Telerik.Web.UI.RadInputControl.prototype._triggerDomEvent= function (eventName, eventSource)
    {
        if (!eventName || eventName == "" || !eventSource)
            return;
        if (eventName == "change")
        {
            this._textBoxElement.RadInputChangeFired = true;
        }
            if (eventSource.fireEvent && document.createEventObject)
        {
            var eventObject = document.createEventObject();
            eventSource.fireEvent(String.format("on{0}", eventName), eventObject);
        }
        else if (eventSource.dispatchEvent)
        {
            var canBubble = true;
            var eventObject = document.createEvent("HTMLEvents");
            eventObject.initEvent(eventName, canBubble, true);
            eventSource.dispatchEvent(eventObject);
        }
        if (eventName == "change")
        {
            this._textBoxElement.RadInputChangeFired = false;
        }
    }
     
     
     
    if (typeof (ValidatorOnChange) == "function" && typeof (ValidatorOnChange_Original) == "undefined")
    {
        ValidatorOnChange_Original = ValidatorOnChange;
     
        ValidatorOnChange = function (event)
        {
            var element;
            if ((typeof (event.srcElement) != "undefined") && (event.srcElement != null))
            {
                element = event.srcElement;
            }
            else
            {
                element = event.target;
            }
     
            if (typeof (element.RadInputValidationValue) != "string" ||
                      (typeof (element.RadInputChangeFired) == "boolean" && element.RadInputChangeFired))
            {
                return ValidatorOnChange_Original(event);
            }  
        }
    }


    Greetings,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 19 Jun 2012 Link to this post

    Thanks, Vasil.

    That seems to have helped.

    We had one section of code that used some Javascript for the validation and I was able to go back to our original code for that page. But for the example I posted here before, I couldn't use the original completely.  I was able to eliminate the use of NumberFormat-GroupSeparator="" but had to keep the RadNumericTextBox attribute for Type set to "Number" instead of the original value of "Currency".
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 19 Jun 2012 Link to this post

    Hello,

    Try to add also this code:
    function ValidatedTextBoxOnKeyPress(event)
    {
        if (event.keyCode == 13)
        {
            ValidatorOnChange(event);
            var element;
            if ((typeof (event.srcElement) != "undefined") && (event.srcElement != null))
            {
                element = event.srcElement;
            }
            else
            {
                element = event.target;
            }
            if (typeof (element.RadInputValidationValue) != "string")
            {
                return AllValidatorsValid(element.Validators);
            }
        }
        return true;
    }

    You could test it, and let us know if it works. Another possible way would be to use code from this forum thread:
    http://www.telerik.com/community/forums/aspnet-ajax/input/problem-with-defaultbutton-in-q2-2012.aspx

    Regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 19 Jun 2012 Link to this post

    Unfortunately, that code won't help in this situation as on these forms in particular, the user clicks a Save button that triggers the validation to occur.
  7. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 22 Jun 2012 Link to this post

    Hello Jerry,

    Could you confirm that the Culture and UICulture on your Page are the same, and that the Validators and NumericTextBoxes has the same culture?
    I am unable to replicate the issue after using the workaround.

    Kind regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  8. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 22 Jun 2012 Link to this post

    Vasil,

    We don't set Culture nor UICulture so they would be whatever the defaults are. I'm assuming "en-US" and "en".  I manually set those values on the main .aspx page for this control and that had no effect.

    As long as I have the Type="Currency" set on the RadNumericTextBox, I get validation errors.  I have to set Type="Number".
  9. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 27 Jun 2012 Link to this post

    Hello,

    We have fixed the issue that was caused the validators to check wrongly value during validation. Please try the 2012.2.626 hotfix of the controls.

    Greetings,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  10. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 27 Jun 2012 Link to this post

    I couldn't test properly in our main app (due to no CDN support in internal builds) but I copied the code in question into a test project and bound it to some test XML data and both types of our validation (JS and asp:comparevalidator) are working fine now.

    Thanks.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017