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

RadDateInput set_newValue in IE7

2 Answers 46 Views
Input
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 28 Apr 2011, 06:35 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Pavel
Telerik team
answered on 02 May 2011, 09:34 AM
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.

0
Eric
Top achievements
Rank 1
answered on 02 May 2011, 06:23 PM
Yes, that was it.  Thank you, Pavel.

Eric
Tags
Input
Asked by
Eric
Top achievements
Rank 1
Answers by
Pavel
Telerik team
Eric
Top achievements
Rank 1
Share this question
or