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

[Solved] Require resources, advanced date, and output errors

5 Answers 154 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 03 Dec 2009, 01:48 AM
Hello. I need help with three things:

  • I need to make it required that a user selects from two resource dropdowns before attempting to submit a new appointment.
  • I need to make it required that the date of the appointment is after today.
  • I need to output error messages if either of these two do not happen.

        protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)  
        {  
            //if the event takes place before today, cancel, preferably with an error message  
            //if the resources are left empty, cancel, preferably with an error message  
            if (e.Appointment.Start <= DateTime.Now)  
            {  
                e.Cancel = true;  
            }  
        }  
 
        protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)  
        {  
            //if the event takes place before today, cancel, preferably with an error message  
            //if the resources are left empty, cancel, preferably with an error message  
            if (e.ModifiedAppointment.Start <= DateTime.Now)  
            {  
                e.Cancel = true;  
            }  
        } 

Using the above functions, I can prevent insertion/editing-in a prior date, but how do I get the scheduler to output an error message?

And how do I require resource selection from dropdown menus AND provide errors for those as well?

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 03 Dec 2009, 11:46 PM
Help! I've gotten this much to work so far:

            //the following should output errors  
 
            if (e.ModifiedAppointment.Subject == String.Empty)  
            {  
                e.Cancel = true;  
            }  
 
            if (e.ModifiedAppointment.Start <= DateTime.Now)  
            {  
                e.Cancel = true;  
            }  
 
            if (e.ModifiedAppointment.Resources.GetResourceByType("Event") == null)  
            {  
                e.Cancel = true;  
            }  
 
            if (e.ModifiedAppointment.Resources.GetResourceByType("Location") == null)  
            {  
                e.Cancel = true;  
            } 

But I need errors to display if any of the above are true.

Please help as I'm stuck at this point.
0
David
Top achievements
Rank 1
answered on 07 Dec 2009, 11:21 PM
I still need help. The form does not output errors.
0
Peter
Telerik team
answered on 08 Dec 2009, 01:10 PM
Hello David,

You can add the error message as a label control in FormCreated. Then you can use jQuery and a hidden field (that will act as a flag) to hide or show it as needed. For example:

<script type="text/javascript">
          function OnClientFormCreated(sender, eventArgs) {
            var showErrorMessage = document.getElementById("showErrorMessage");
            if(showErrorMessage.value == "false")
                $telerik.$(".errorMessageTimepickerCss").hide();
            else
                $telerik.$(".errorMessageTimepickerCss").show();
             
        }
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:HiddenField ID="showErrorMessage" runat="server" Value="false"/>
      
    <telerik:RadScheduler ID="RadScheduler1" runat="server" 
        onappointmentupdate="RadScheduler1_AppointmentUpdate" 
        onformcreated="RadScheduler1_FormCreated"
        OnClientFormCreated="OnClientFormCreated"
        >
        <AdvancedForm Modal="true" />
    </telerik:RadScheduler>
.errorMessageTimepickerCss
    {
      color:Red;
    }

 

protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
    {
        if (e.Container.Mode == SchedulerFormMode.AdvancedEdit || e.Container.Mode == SchedulerFormMode.AdvancedInsert)
        {
            Label errorMessageTimepicker = new Label();
            errorMessageTimepicker.Text = "start date should be after today";
            errorMessageTimepicker.CssClass = "errorMessageTimepickerCss";
             
            Panel advancedPanel = (Panel)e.Container.FindControl("BasicControlsPanel");
            if(advancedPanel.FindControl("errorMessageTimepicker") == null)
                advancedPanel.Controls.Add(errorMessageTimepicker);
        }
    }
    protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
    {
        if (e.ModifiedAppointment.Start <= DateTime.Now)
        {
            e.Cancel = true;
            showErrorMessage.Value = "true";
        }
        else
            showErrorMessage.Value = "false";
    }

Let us know  if this approach can be applied in your case.

Regards,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
David
Top achievements
Rank 1
answered on 08 Dec 2009, 10:48 PM
That looks like it'll work. I'll give it a try shortly.

That's quite a bit of work, though, and it's not transparent for others who may have the same problem. Would it be possible to make a resource property such as IsRequired and another possibly for ResourceNotSpecifiedError text? You guys can probably come up with a better way to do that, but it'd be a lot easier to say that Resource Location is required and that the Not Specified Error Text is "No Location Specified".
0
Peter
Telerik team
answered on 11 Dec 2009, 04:20 PM
Hi David,

Thank you for this suggestion. I have logged your suggestion and we will consider implementing such a feature.


Kind regards,
Peter
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Scheduler
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Peter
Telerik team
Share this question
or