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

A CustomValidator for the subject field

1 Answer 59 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Mehmet
Top achievements
Rank 1
Mehmet asked on 24 Jun 2014, 12:30 AM
01.protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
02.        {
03.            if ((e.Container.Mode == SchedulerFormMode.AdvancedEdit) || (e.Container.Mode == SchedulerFormMode.AdvancedInsert))
04.            {
05.                CustomValidator validatorForDescription = new CustomValidator();
06.                RadScheduler scheduler = (RadScheduler)sender;
07.                validatorForDescription.ValidationGroup = scheduler.ValidationGroup;
08.                validatorForDescription.ControlToValidate = "Subject";
09.                validatorForDescription.ErrorMessage = "Job Title should be indicated !";
10.                validatorForDescription.ClientValidationFunction = "validationFunction";
11.                //validatorForDescription.Display = ValidatorDisplay.Dynamic;
12.                //e.Container.Controls.Add(validatorForDescription);               
13.                (e.Container.FindControl("Subject") as RadTextBox).Parent.Controls.Add(validatorForDescription);
14. 
15.                CheckBox allDayCheckbox = (CheckBox)e.Container.FindControl("AllDayEvent");
16.                allDayCheckbox.Style.Add("visibility", "hidden");
17.            }
18.        }
01.<telerik:RadScheduler runat="server" ID="RadScheduler1" TimeZoneOffset="10:00:00" OnAppointmentInsert="RadScheduler1_AppointmentInsert" OverflowBehavior="Expand" Height="100%"
02.               OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" OnAppointmentDelete="RadScheduler1_AppointmentDelete"
03.               DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End" OnFormCreated="RadScheduler1_FormCreated"
04.               FirstDayOfWeek="Monday" LastDayOfWeek="Sunday" TimeZoneID="AUS Eastern Standard Time" DisplayDeleteConfirmation="False" SelectedDate="2014-06-24">
05.               <ExportSettings>
06.                   <Pdf PageTopMargin="1in" PageBottomMargin="1in" PageLeftMargin="1in" PageRightMargin="1in"></Pdf>
07.               </ExportSettings>
08. 
09.               <AdvancedForm Modal="true" />
10.               <Localization AdvancedNewAppointment="Add a new job" AdvancedSubject="Job Title" AdvancedEditAppointment="Edit Job" AllDay="false" />
11.               <TimelineView UserSelectable="false" />
12.               <TimeSlotContextMenuSettings EnableDefault="true" />
13.               <AppointmentContextMenuSettings EnableDefault="true" />
14.               <Reminders Enabled="false" />
15.               <AppointmentTemplate>
16.                   <div>
17.                       <%# Eval("Subject") %>
18.                       <br />
19.                   </div>
20.               </AppointmentTemplate>
21.           </telerik:RadScheduler>

Here is my code behind and the  html side. Could anybody tell me why I cannot get a custom validator error message when I click OK on my Insert/Edit Form ?
thank you

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 25 Jun 2014, 02:02 PM
Hi Mehmet,

The reason that you're not observing the default behavior of the validator is that RadScheduler automatically intercepts and overrides all advanced form validators in order to provide the custom validation styling in the
form. To overcome this you have to exclude your custom validator with the following javascript:
if (Telerik.Web.UI.Scheduling && Telerik.Web.UI.Scheduling.AdvancedTemplateBase) {
    Telerik.Web.UI.Scheduling.AdvancedTemplateBase.prototype._validatorIsInTemplate = function(validator) {
        return $(validator).parents().is("#" + this._schedulerElementId) && !$(validator).hasClass("customValidator");
    }
}

Next you have to add the "customValidator" class to your validator:
CustomValidator validatorForDescription = new CustomValidator();
validatorForDescription.CssClass = "customValidator";

One last thing is that due to the layout of the advanced form, the validation message in this setting will appear to the right of the textbox, and will not be visible. To fix this the following style must be added:
.customValidator {
    display:block;
}

I've also attached a small sample website page demonstrating the finished result.

Regards,
Bozhidar
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.

 
Tags
Scheduler
Asked by
Mehmet
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or