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

Possible to capture Resource selection to Subject?

3 Answers 9 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 01 Sep 2013, 10:46 PM
I have two resource dropdowns on my scheduler, when the user adds or modifies a schedule. There is the room as one resource, and the teacher as a second resource. How can I capture the teacher name selected from the teacher resource and populate the Subject box during selection time? This would happen client side I presume. I'm just not good at javascript, so have no clue how to do it.

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 05 Sep 2013, 07:30 AM
Hello,

Please use the following code snippet in order to achieve the desired scenario. Please note that for sample purposes I am using resource called "User" but in your case it would be "Teacher".
//markup code

<telerik:RadScheduler runat="server" ID="RadScheduler1" ....  OnFormCreated="RadScheduler1_FormCreated">
    <ResourceTypes>
        <telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="UserID" Name="User" TextField="UserName" />
    </ResourceTypes>
</telerik:RadScheduler>

//code behind
protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
    {
 
        if ((e.Container.Mode == SchedulerFormMode.AdvancedEdit) || (e.Container.Mode == SchedulerFormMode.AdvancedInsert))
        {
            //finds the RadComboBox representing the user resource ( in your case it would be ResTeacher)
            RadComboBox userResource = e.Container.FindControl("ResUser") as RadComboBox;
            //this line of code will subscribe for the the client-side event fired when user selects a new value from the RadComboBox control
            userResource.OnClientSelectedIndexChanging = "OnClientSelectedIndexChanging";
        }
    }

//JavaScript

function OnClientSelectedIndexChanging(sender, args) {        
    var $ = $telerik.$;
    //retrieves the subject field as jQuery object
    var subjectField = $("[id$='Subject']");
    //this is the value of the selected item from the RadComboBox
    var selectedUserName = args.get_item().get_text();
    //changes the subject text box to the selected item text value
    subjectField.val(selectedUserName);
}

Please find here more information about accessing different elements within the advanced form and how you can manipulate them.

Hope that this helps.

Regards,
Boyan Dimitrov
Telerik
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 the blog feed now.
0
Steve
Top achievements
Rank 1
answered on 07 Sep 2013, 11:27 PM
Thanks for the code. It only partially worked for me. It populated the subject line, but it wouldn't close the form.
I select a teacher, and it populates the subject. I click the save button and all the form elements clear out, and the start and end time are set to the current date and time. The form doesn't close. I have to click the cancel button to get the form to close. I looked in the database and the subject is populated with the teacher name, so I know it's working otherwise.
0
Boyan Dimitrov
Telerik team
answered on 12 Sep 2013, 06:24 AM
Hello,

I am afraid that I am not able to replicate the described behavior at my side.
A possible reason for such behavior might be a JavaScript error preventing the RadScheduler from behaving as expected when appointment is updated. Could you please inspect the application behavior when appointment is being saved with any browsers developer tools and provide the JavaScript error if any? Could you please clarify whether you have implemented any custom logic to handle the form creation or appointment update?


Regards,
Boyan Dimitrov
Telerik
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 the blog feed now.
Tags
Scheduler
Asked by
Steve
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Steve
Top achievements
Rank 1
Share this question
or