RadDatePicker with CustomValidator

8 posts, 0 answers
  1. Carlo
    Carlo avatar
    10 posts
    Member since:
    Dec 2011

    Posted 23 Sep 2014 Link to this post

    Hello,

    I was attempting to use a CustomValidator with a RadDatePicker and the validation function seems not to function. The same date picker has both a RequiredFieldValidator and CustomValidator. What I'm finding is that the custom validation client script is never fired. I'm not getting any javascript function errors either. The required field validator does however fire and properly prevents postback.

    Code basically looks like this

    <telerik:RadDatePicker runat="server" ID="dpkStart"  Culture="<%# vRIS.Business.Utility.DateFormatProvider.RISCulture %>" MinDate="<%# DateTime.Now.Date %>" SelectedDate="<%# DateTime.Now.Date %>" />
    <asp:RequiredFieldValidator runat="server" ID="StartSearchingValidator" EnableClientScript="True" ControlToValidate="dpkStart" ValidationGroup="Availability" Display="Dynamic" Enabled="true" ErrorMessage="Search beginning is required" SetFocusOnError="True"  />
    <asp:CustomValidator ID="valChecks" ControlToValidate="dpkStart" EnableClientScript="true" Enabled="true" ValidationGroup="Availability" Display="Dynamic" ClientValidationFunction="selfScheduleAvailability.validateAvailabilitySelection" ErrorMessage="Please select an availability day/time" runat="server"></asp:CustomValidator>

    ------- In a top level control, the submit button can be found.
    <Portal:SubmitButton ID="btnAdvToConfirmation" Text="Schedule" OnClick="btnAdvToConfirmation_Click" ValidationGroup="Availability" CausesValidation="true" Width="130" runat="server" />
  2. Carlo
    Carlo avatar
    10 posts
    Member since:
    Dec 2011

    Posted 24 Sep 2014 in reply to Carlo Link to this post

    Seems like the custom validator only fails to fire when I am automatically switching tabs in a rad tab view as part of a wizard. So more backgroud details. This control is contained in part of a 3 step wizard. The first step lets you choose a location, the second availability then the last is a confirmation. 

    What I have found is if I switch tabs using the RadTabStrip buttons then the custom validator **does** fire as expected. (You can only do this when you've finished the process). But if you click the "Next" button from the first screen, and land on the second. This is when the custom validator fails to fire. To switch the tabs 2 things happen. 

    In code behind TabStrip.SelectedIndex = Index; Multipage.SelectedIndex = index. Then a script is registered using ScriptManager which updates the tab strip UI (this is ajaxified using RadAjaxLoadingPanel) using client side functions. The JS code for that looks like this:

        function appointmentWizard_nextTab(tabID, pageIndex) {
            var multipageID = '<asp:literal id="litMultiPage" runat="server" />';
            var tabstripID = '<asp:literal id="litTabStrip" runat="server" />';
            var multiPage = $find(multipageID);
            var tabStrip = $find(tabstripID);
            if (multiPage != null) {
                var pageview = multiPage.get_pageViews().getPageView(pageIndex);
                if (pageview != null) {
                    pageview.set_selected(true);
                }
            } //End if(multiPage != null...
            if (tabStrip != null) {
                var tabs = tabStrip.get_tabs();
                var tab = tabs.getTab(tabID);
                if (tab != null) {
                    tab.set_enabled(true);
                    tab.select();
                }
            } //End if(tabStrip != null...
        } //End function appointmentWizard_nextTab(tabNum...
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 29 Sep 2014 Link to this post

    Hello Carlo,

    The CustomValidator and Range/Compare validators fire only if there is value in the input. In case it is empty they will not fire.

    The DatePicker uses separate validation Value that it pass to the validators. It is always in format "yyyy-MM-dd-hh-mm-ss" and it is independent of the current Culture. In case the Date is not valid in the picker, it will have empty validation value, and in this case only the RequiredFieldValidator will fire.

    Regards,
    Vasil
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Carlo
    Carlo avatar
    10 posts
    Member since:
    Dec 2011

    Posted 29 Sep 2014 in reply to Vasil Link to this post

    Yes, well aware. The date picker has a required field validator (which does fire) on it. It also loads prepopulated with a value. So in theory there should be no case in which custom validator does not fire
    .
  6. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 29 Sep 2014 Link to this post

    Hi Carlo,

    The RequiredFieldValidator fires every time. But if the input is empty (or have string that is not date), the CustomValidator will not fire.

    You can test it in this online demo:
    http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/validation/defaultcs.aspx

    Regards,
    Vasil
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Carlo
    Carlo avatar
    10 posts
    Member since:
    Dec 2011

    Posted 29 Sep 2014 in reply to Vasil Link to this post

    Again, as I have noted previously. I am aware that custom validator doesn't fire if the date field is empty. I don't expect it to. To be clear, what I was saying is that per implementation it is not possible for the date field to be empty. The date field is not only initialized with a value, but as I noted it does **also** have a required field validator preventing postback with an empty value. This date picker can not be empty, and will never be empty.
  8. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 29 Sep 2014 Link to this post

    Hi Carlo,

    Please excuse me, but I was confused by your first post that says one of the validators fire and the other one not.

    I believe in your case both of the validators are not firing. And this is because you do request when the view is changed, without actually click any button.

    The buttons could have CausesValidation="true/false", and in case the property is false, they do not perform validation. If you however perform Ajax or PostBack manually, you will need to call Page_IsValid manually, because it is equal to performing callback from button that does not have CausesValidation set to true.

    The issue is not particually related with the RadDatePicker, you will get the same behavior with asp:TextBox as well.

    Regards,
    Vasil
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. Carlo
    Carlo avatar
    10 posts
    Member since:
    Dec 2011

    Posted 29 Sep 2014 in reply to Vasil Link to this post

    I believed what you say to be the case initially, but just for fun I went ahead and deleted the contents of the RadDatePicker. The required field validator *did* fire and prevent the post back. But if you fill the box, the custom validator (which is actually checking check boxes on the page) does *not* fire regardless.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017