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

RadDatePicker with CustomValidator

7 Answers 408 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Carlo
Top achievements
Rank 1
Carlo asked on 23 Sep 2014, 06:44 PM
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" />

7 Answers, 1 is accepted

Sort by
0
Carlo
Top achievements
Rank 1
answered on 24 Sep 2014, 12:55 PM
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...
0
Vasil
Telerik team
answered on 29 Sep 2014, 08:07 AM
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.

 
0
Carlo
Top achievements
Rank 1
answered on 29 Sep 2014, 09:45 AM
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
.
0
Vasil
Telerik team
answered on 29 Sep 2014, 11:37 AM
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.

 
0
Carlo
Top achievements
Rank 1
answered on 29 Sep 2014, 12:01 PM
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.
0
Vasil
Telerik team
answered on 29 Sep 2014, 12:45 PM
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.

 
0
Carlo
Top achievements
Rank 1
answered on 29 Sep 2014, 12:53 PM
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.
Tags
Calendar
Asked by
Carlo
Top achievements
Rank 1
Answers by
Carlo
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or