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

Control assigns valid date on tab

1 Answer 30 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Craig Hinkel
Top achievements
Rank 1
Craig Hinkel asked on 08 Jan 2009, 09:19 PM
I'm using the RadDatePicker control and let's say I enter '1' into the control and tab away. The control automatically assigns '1/1/2009' to the control. We do not want this, is there a way to stop this and make it invalid so the user has to enter a valid date?

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 12 Jan 2009, 12:40 PM
Hello Craig,

One possible solution would be to intercept the OnValueChanging event of the date input (part of the date picker control), check whether the newValue argument can be parsed to a valid date and cancel the operation if this condition is not met.

Here is a sample code implementation:

            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <script type="text/javascript">  
            function ValueChanging(sender, eventArgs)  
            {  
             if(new Date(eventArgs.get_newValue()) == "NaN")  
             {  
              eventArgs.set_cancel(true);  
             }   
            }  
            </script> 
            <telerik:RadDatePicker ID="RadDatePicker1" runat="server">  
                <DateInput runat="server">  
                    <ClientEvents OnValueChanging="ValueChanging"/>  
                </DateInput> 
            </telerik:RadDatePicker> 

In order to provide user-friendly notification that the entered value is invalid and has to be changed, consider attaching RadToolTip to the date input and utilize the approach presented in this blog post.

Let me know whether these directions are helpful.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Calendar
Asked by
Craig Hinkel
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or