RadDatePicker Empty or Valid Date

4 posts, 0 answers
  1. skysailor
    skysailor avatar
    113 posts
    Member since:
    Jul 2007

    Posted 29 Nov 2007 Link to this post

    Hi,
    I would like to be about to validate that the date entered into a date picker control is either blank or a valid date. The examples use a required field validator to check that a valid date is entered. That works fine. But I would like the user to be able to enter a blank date and for that to be valid as well. But if they have entered a date then flag it as an error if the date is invalid.
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 30 Nov 2007 Link to this post

    Hello skysailor,

    We would suggest you the following modification of this code library project here:

    <script type="text/javascript">  
    var invalidInput = false;  
    function OnDateSelected(sender, args)  
    {  
        invalidInput = false;  
    }  
     
    function OnError(sender, args)  
    {  
        invalidInput = true;  
    }  
     
    function CustomValidate(sender, args)  
    {  
        if (invalidInput)  
            args.IsValid = false;  
     
    function OnBlur(sender, args) 
        if (sender.GetTextBoxValue() == "") 
        { 
            invalidInput = false
        }  
    </script> 
     
    <radcln:RadDatePicker ID="RadDatePicker1" runat="server" MinDate="2006/12/31" MaxDate="2009/1/1"
        <ClientEvents OnDateSelected="OnDateSelected" /> 
        <DateInput ClientEvents-OnError="OnError" ClientEvents-OnBlur="OnBlur" /> 
    </radcln:RadDatePicker> 
    <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="CustomValidate" 
        ErrorMessage="*" /> 
    <asp:Button ID="Button1" runat="server" Text="Button" /> 


    Hope this helps.


    Best wishes,
    Manuel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. James
    James avatar
    44 posts
    Member since:
    Jan 2012

    Posted 23 Jan 2013 Link to this post

    I am trying this example and I never get the CustomValidator to execute.  Can someone help me with what I am doing wrong here?

    var invalidInput = false;
    function OnDateSelected(sender, args) {
        invalidInput = false;
    }
     
    function onDateError(sender, args) {
       invalidInput = true;
    }
     
    function CustomValidate(sender, args) {
        if (invalidInput)
           args.IsValid = false;
    }
     
    function onBlur(sender, args) {
        if (sender.get_textBoxValue() == "") {
            invalidInput = false;
         }
    } 
    
    
    <telerik:RadDatePicker ID="rdpStoreNewOpenDate" runat="server" Culture="en-US" DbSelectedDate='<%# Bind("NewOpenDate") %>' ShowPopupOnFocus="False" Skin="Simple">
        <Calendar Skin="Simple" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x"></Calendar>
        <DateInput DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy" ClientEvents-OnError="onDataError" ClientEvents-OnBlur="onBlur">
             <ClientEvents OnError="onDateError" />
        </DateInput>
        <DatePopupButton HoverImageUrl="" ImageUrl="" />
    </telerik:RadDatePicker>
    <asp:CustomValidator runat="server" ID="cvRDPStoreNewOpenDate" ClientValidationFunction="CustomValidate" ErrorMessage="*" ControlToValidate="rdpStoreNewOpenDate" />
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jan 2013 Link to this post

    Hi,

    Try the following code snippet to achieve your scenario.

    ASPX:
    <telerik:RadDatePicker ID="rdpStoreNewOpenDate" runat="server" Culture="en-US" ShowPopupOnFocus="False" ClientEvents-OnDateSelected="OnDateSelected" Skin="Simple" DbSelectedDate='<%# Bind("NewOpenDate") %>' >
        <Calendar Skin="Simple" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" runat="server" ViewSelectorText="x">
        </Calendar>
        <DateInput DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy" ClientEvents-OnError="onDataError" runat="server" ClientEvents-OnBlur="onBlur">
            <ClientEvents OnError="onDateError" />
        </DateInput>
        <DatePopupButton HoverImageUrl="" ImageUrl="" />
    </telerik:RadDatePicker>
    <asp:CustomValidator runat="server" ID="cvRDPStoreNewOpenDate" ClientValidationFunction="CustomValidate" ErrorMessage="*" />
    <asp:Button ID="Button2" runat="server" Text="Button" />

    JS:
    <script type="text/javascript">
        var invalidInput = true;
        function OnDateSelected(sender, args) {
            invalidInput = false;
        }
        function onDateError(sender, args) {
            invalidInput = true;
        }
        function CustomValidate(sender, args) {
            if (invalidInput)
                args.IsValid = false;
            else
                args.IsValid = true;
        }
        function onBlur(sender, args) {
            if (sender.get_textBoxValue() == "") {
                invalidInput = true;
            }
        }
    </script>

    Hope this helps.

    Regards,
    Princy.
Back to Top