Date guessing

5 posts, 1 answers
  1. TriZetto
    TriZetto avatar
    17 posts
    Member since:
    Jul 2006

    Posted 18 Aug 2009 Link to this post

    Hello,
    If I enter "30/22/09" into the first control in this demo, it gets updated to be "9/30/2022" rather than displaying an error indicating the date is invalid. If I enter "9", it gets changed to "8/9/2009". Is there a way to disable this and just show this as an invalid date?
    Thanks
    -marcos
  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 19 Aug 2009 Link to this post

    Hello TriZetto,

    You can cancel the ValueChanging event when the value is not considered as a valid date:
    <script type="text/javascript"
        function valueChanging(sender, args) 
        { 
            if (new Date(args.get_newValue()) == "NaN"
                args.set_cancel(true); 
        } 
    </script> 

    <telerik:RadDatePicker ID="RadDatePicker1" runat="server"
        <DateInput> 
            <ClientEvents OnValueChanging="valueChanging" /> 
        </DateInput> 
    </telerik:RadDatePicker> 

    Regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. TriZetto
    TriZetto avatar
    17 posts
    Member since:
    Jul 2006

    Posted 19 Aug 2009 Link to this post

    Thank you for your reply, but this does not change the behavior of the control. It still changes
    "30/22/09" to "9/30/2022"
    "9" to "8/9/2009"
    "a4" to "9/30/2022"

    To me the input is all invalid given the current culture, but I do not see a way of indicating this to the user.  In you suggested solution,
    new Date(args.get_newValue()) for any of these answers results in a valid date (today's date).

    I suppose in this event handler I can try to match the string with a date regular expression. But I am wondering if there is an alternative.
    Thanks
    -marcos
  4. Answer
    Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 24 Aug 2009 Link to this post

    Hello TriZetto,

    You can handle such data by overriding the built-in date parser engine:
    <script type="text/javascript"
        Telerik.Web.UI.RadDateInput.prototype.parseDate = function(value, baseDate) 
        { 
            if (new Date(value) != "NaN"
                return value; 
        } 
    </script> 

    <telerik:RadDatePicker ID="RadDatePicker1" runat="server"
        <DateInput> 
            <ClientEvents /> 
        </DateInput> 
    </telerik:RadDatePicker> 

    I hope this helps.

    Kind regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. sara r
    sara r avatar
    7 posts
    Member since:
    Mar 2010

    Posted 10 Mar 2010 Link to this post

    hi
    i have a similar issue. but adding this
    <script type="text/javascript"
        Telerik.Web.UI.RadDateInput.prototype.parseDate = function(value, baseDate) 
        { 
            if (new Date(value) != "NaN"
                return value; 
        } 
    </script> 
    causes a js error.
    It doesnt solve the issue.
    In the textbox if i enter 1/5/19 it automatically fills 01/05/2019. when i clear that and tried to enter some other invald date, it gives me the previously populated date ie, 01/05/2019.
    Please help
Back to Top