RadDatePicker Required Validation using RadInputManager

8 posts, 1 answers
  1. eri indrawan
    eri indrawan avatar
    2 posts
    Member since:
    Aug 2009

    Posted 30 Mar 2012 Link to this post

    I love the "warning icon" when using RadInputManager to validate a required field, rather than the asp:RequiredFieldValidation text message. But somehow i can't validate RadDatePicker with RadInputManager.
    I've been looking the solution for this but the example that i found always use asp:RequiredFieldValidation.

    Could you provide an example to validate RadDatePicker with RadInputManager ?
    or how can I get the "warning icon" when the RadDatePicker is required?
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Mar 2012 Link to this post

    Hi,

    Here is a sample code snippet I tried to achieve validation of RadDatePicker on button click. Please have a look into the following code.

    ASPX:
    <telerik:RadDatePicker ID="RadDatePicker" runat="server"  ></telerik:RadDatePicker>
    <asp:Button ID="Button1" Text="Submit" runat="server" OnClientClick="OnClientClick(); return false;"/>

    JS:
    <script type="text/javascript">
        function OnClientClick()
         {
            var DatePicker = $find("<%= RadDatePicker1.ClientID %>");
            if (DatePicker.get_selectedDate() == null)
             {
                DatePicker.get_dateInput()._invalid = true;
                DatePicker.get_dateInput().updateCssClass();
             }
            else
             {
                DatePicker.get_dateInput()._invalid = false;
                DatePicker.get_dateInput().updateCssClass();
             }
        }
    </script>

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. eri indrawan
    eri indrawan avatar
    2 posts
    Member since:
    Aug 2009

    Posted 02 Apr 2012 Link to this post

    Hi Princy,

    This workaround is works,
    Thanks!
  5. Ivan
    Ivan avatar
    5 posts
    Member since:
    Apr 2012

    Posted 05 Apr 2012 Link to this post

    ASPX:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server"  ></telerik:RadDatePicker>
    <asp:Button ID="Button1" Text="Submit" runat="server" ValidationGroup="Save" />
    <asp:Button ID="Button2" Text="Cancel" runat="server"/>

    JS:
    <script type="text/javascript">
        $("form").submit(function() {
            var DatePicker = $find("<%= RadDatePicker1.ClientID %>");
            if (DatePicker.get_selectedDate() == null)
             {
                DatePicker.get_dateInput()._invalid = true;
                DatePicker.get_dateInput().updateCssClass();
                     return false;
             }
            else
             {
                DatePicker.get_dateInput()._invalid = false;
                DatePicker.get_dateInput().updateCssClass();
                return true;
             }
        });
    </script>

    It is my current code. but how i can add a validation group ?
  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 10 Apr 2012 Link to this post

    Hi Ivan,

    I reviewed your code but I was not able to correctly understand what your exact requirements are? Could you please elaborate a bit more eon your scenario and what is the final results you are aiming.?

    Greetings,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Ivan
    Ivan avatar
    5 posts
    Member since:
    Apr 2012

    Posted 13 Apr 2012 Link to this post

    Hi Maria,

    I just want to add "warning icon" to RadDatePicker but using ValidationGroup

    ASPX:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" ValidationGroup="Save"  ></telerik:RadDatePicker>
    <asp:Button ID="ButtonSubmit" Text="Submit" runat="server" ValidationGroup="Save" />
    <asp:Button ID="ButtonCancel" Text="Cancel" runat="server"/>

    If I click on "ButtonSubmit", the "RadDatePicker" show the "warning icon"
    but when i click "ButtonCancel", the "warning icon" not shown.
    Can you provide me the valid code ?
  8. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 18 Apr 2012 Link to this post

    Hello,

    The behaviour you are describing is expected in your case. You have set the same validation group for the RadDatePicker and the "Submit" button and no validation group for the "Cancel" button. Note that the "Cancel" button should have the same validation group in order to trigger validation for the RadDatePicker control.

    Regards,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Ivan
    Ivan avatar
    5 posts
    Member since:
    Apr 2012

    Posted 18 Apr 2012 Link to this post

    Hello,

    I think we have miss understanding about the requirement, the solution that Princy gave is correct.
    How do i trigger the script :
    <script type="text/javascript">
        function OnClientClick()
         {
            var DatePicker = $find("<%= RadDatePicker1.ClientID %>");
            if (DatePicker.get_selectedDate() == null)
             {
                DatePicker.get_dateInput()._invalid = true;
                DatePicker.get_dateInput().updateCssClass();
             }
            else
             {
                DatePicker.get_dateInput()._invalid = false;
                DatePicker.get_dateInput().updateCssClass();
             }
        }
    </script>
    on each RadDatePicker that has the same ValidationGroup.

    Thanks,
    Ivan Yanitra
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017