Validate Resource Drop Downs

9 posts, 0 answers
  1. Nick
    Nick avatar
    11 posts
    Member since:
    Jan 2009

    Posted 01 Mar 2009 Link to this post

    I'm looking for a way to validate the Rooms drop down on the Advanced form. I want to required that a room has to be selected when creating the appointment and then show an indicator as to which field is required. Can this be done with the scheduler control?
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 04 Mar 2009 Link to this post

    Hello Nick,

    You can add validation to the resource dropdownlist control using custom user controls as shown in the Customizing the Advanced Template example.

    An easier solution is to simply handle FormCreated and remove the empty ("-") item from the dropdownlist control. For example, if you have a resource type with Name="Room" you can use the following code:

     protected void RadScheduler1_FormCreated(object sender, Telerik.Web.UI.SchedulerFormCreatedEventArgs e)  
        {  
            if ((e.Container.Mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) || (e.Container.Mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert))  
            {  
                DropDownList resDdl = e.Container.FindControl("ResRoom"as DropDownList;  
                resDdl.Items.RemoveAt(0);             
            }  
        } 



    Best wishes,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. John Yoo
    John Yoo avatar
    4 posts
    Member since:
    Jul 2009

    Posted 23 Jul 2009 Link to this post

    Peter,
    I've tried to perform these steps myself, however I can't get it to work (I'm using the Q2 09 release). 
    My resource's name is "Calendar", and I tried the call to FindControl with both the "Calendar" name and the "ResCalendar" name.
    Here's my code:

            protected void scheduleDisplay_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
            {
                if (e.Container.Mode == SchedulerFormMode.AdvancedEdit ||
                    e.Container.Mode == SchedulerFormMode.AdvancedInsert)
                {
                    Control panel = e.Container.FindControl("AdvancedControlsPanel") as Control;
                    Control resourceControlContainer = panel.FindControl("ResourceControls") as Control;
                    DropDownList calendarResourceDropDown = e.Container.FindControl("ResCalendar") as DropDownList;
                    if (calendarResourceDropDown == null) // this is from a different post
                        calendarResourceDropDown = resourceControlContainer.FindControl("ResCalendar") as DropDownList;
                    calendarResourceDropDown.Items.RemoveAt(0); // here it is still null
                }
            }
  4. John Yoo
    John Yoo avatar
    4 posts
    Member since:
    Jul 2009

    Posted 23 Jul 2009 Link to this post

    I actually figured it out, it works with the ResCalendar, but the type of the control is not DropDownList but rather RadComboBox.
    Never mind.
  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 24 Jul 2009 Link to this post

    Hi John,

    Yes, with Q2 2009 we have replaced the resour dropdownlist with RadComboBox. We might need to document this better.

    All the best,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Dan Green
    Dan Green avatar
    4 posts
    Member since:
    Mar 2008

    Posted 19 Feb 2013 Link to this post

    I need to do this, but I am using the web service binding and OnFormCreated event is not fired at all.
  7. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 22 Feb 2013 Link to this post

    Hello Dan,

     
    I case of Web Service binding you can use onClientFormCreated event in order to get the client object of the appropriate resource RadCombobox in a similar way as is it is explained in this help article.

    Hope this will be helpful.

    Greetings,
    Plamen
    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.
  8. Dan Green
    Dan Green avatar
    4 posts
    Member since:
    Mar 2008

    Posted 28 Feb 2013 Link to this post

    Following the example I have tried to remove the default item without any luck. Here is my code.

    function clientFormCreated(sender, args) {
        var mode = args.get_mode();
        if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
            mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
            var repComboBox = $find($telerik.$("[id$='Form_ResRep']").attr("id"));
            console.log(repComboBox.get_items().getItem(0).get_text());
            repComboBox.get_items().removeAt(0);
            console.log(repComboBox.get_items().getItem(0).get_text());
        }
    }

    The fist console.log == "-" and the second one = "Connor Flynn", which is the first option in the list after the default value.
    So it is removed, but it is not reflected in the UI, the list still contains the default value of "-".
  9. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 04 Mar 2013 Link to this post

    Hi Dan,

     
    You need to set some time out when removing the item so that is performed after the default loading of resources is done. Here is the code that should work for you:

    function OnClientFormCreated(sender, args) {
     
                   var mode = args.get_mode();
                   if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
                       mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
                       var repComboBox = $find($telerik.$("[id$='Form_ResRep']").attr("id"));
                       setTimeout(function myfunction() {
                           repComboBox.get_items().removeAt(0);
     
                       }, 200);
                   }
               }

    Hope this will be helpful.

    Regards,
    Plamen
    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.
Back to Top