RadDateInput set_newValue in IE7

3 posts, 1 answers
  1. Eric
    Eric avatar
    2 posts
    Member since:
    Jun 2010

    Posted 28 Apr 2011 Link to this post

    I have this code to allow users to enter dates into a RadDateInput using the formats mdyy or mddyy, reformatting them as mm/dd/yyyy.  It works great for Firefox and IE8, but it does not work for IE7.  I walked through the code, and set_newValue is in fact fired, but it does not change the date, and it handles those formats as invalid.

    I also tried hacking it by setting the textbox and hidden fields directly, but that failed in pretty short order.

    Has anyone implemented set_newValue in IE7?

    <script type="text/javascript">
        function PreParseDate(sender, eventArgs)
        {
            var reSpace = /\s*/g;
            var reMdyy = /^\d{4}$/;
            var reMddyy = /^\d{5}$/;
            var val = eventArgs.get_newValue().replace(reSpace, '');
            
            if (reMdyy.test(val))
            {           
                eventArgs.set_newValue('0' + val[0] +
          '/0' + val[1] +
          '/' + (val[2] > 1 ? '19' : '20') + val[2] + val[3]);
            }
            else if (reMddyy.test(val))
            {
                eventArgs.set_newValue('0' + val[0] +
          '/' + val[1] + val[2] +
          '/' + (val[3] > 1 ? '19' : '20') + val[3] + val[4]);
            }
        }
    </script>
    <telerik:RadDateInput ID="rdiDOB" runat="server">
        <ClientEvents OnValueChanging="PreParseDate" />
    </telerik:RadDateInput>

    Thank you,

    Eric
  2. Answer
    Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 02 May 2011 Link to this post

    Hi Eric,

    The problem is not related to our control and is caused by the way different IE versions interpret the javascript code you are using. In the older IE7 val[0] returns "undefined". You can verify this with this simple script:
    function pageLoad()
    {
        var num = "123456";
        alert(num[0]);
        alert(num[5]);
    }

    You can workaround the problem by using the charAt() method of the javascript string object:
    else if (reMddyy.test(val))
    {
        eventArgs.set_newValue('0' + val.charAt(0) +
        '/' + val.charAt(1) + val.charAt(2) +
        '/' + (val.charAt(3) > 1 ? '19' : '20') + val.charAt(3) + val.charAt(4));
    }


    Regards,
    Pavel
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Eric
    Eric avatar
    2 posts
    Member since:
    Jun 2010

    Posted 02 May 2011 Link to this post

    Yes, that was it.  Thank you, Pavel.

    Eric
Back to Top