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

Issue with RequestItems on related combos

10 Answers 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Stargazer
Top achievements
Rank 2
Stargazer asked on 03 Jul 2013, 03:09 PM
Hello!

I'm having an issue with my scenario and It seems I can't resolve it. I have a button to copy data from a form to another. Actually, correctly speaking, it is the same form, but fields are in separate tabs.

This button uses javascript on client to copy the data. With text boxes there is no problem, very straight forward. The problem is with combos.

In tab1, there is 3 combos. The first one is bound server side. After selection, there is a call to clientside RequestItems which populates the next combo, then after selection on the second one, same thing for the third one. All works well and perfect.

Te problem is when I try to copy those selections to another 3 combos on tab2. Here is the javascript code snippet:
cmbDistritoEE.trackChanges();
cmbDistritoEE.get_items().getItem(cmbDistritoPai.get_selectedIndex()).select();
var item = cmbDistritoEE.get_items().getItem(cmbDistritoPai.get_selectedIndex());
cmbDistritoEE.commitChanges();
cmbConcelhoEE.requestItems(item.get_value(), false);
 
cmbConcelhoEE.trackChanges();
cmbConcelhoEE.get_items().getItem(cmbConcelhoPai.get_selectedIndex()).select();
item = cmbConcelhoEE.get_items().getItem(cmbConcelhoPai.get_selectedIndex());
cmbConcelhoEE.commitChanges();
cmbFreguesiaEE.requestItems(item.get_value(), false);
 
cmbFreguesiaEE.trackChanges();
cmbFreguesiaEE.get_items().getItem(cmbFreguesiaPai.get_selectedIndex()).select();
item = cmbFreguesiaEE.get_items().getItem(cmbFreguesiaPai.get_selectedIndex());
cmbFreguesiaEE.commitChanges();

The issue occurs when RequesItems is called oncmbConcelhoEE combobox and in the following lines, when get_items() is called on cmbConcelhoEE there are no items. After a "second pass" (i.e. clicking second time on the button) there are items. This is because of the RequestItems callback mechanism.

My question: how do I manage to do this client side?

Best regards!

10 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 08 Jul 2013, 11:31 AM
Hello Stargazer,

As you well guessed, the issue you are facing is because you attempt to access the items during the callback mechanism execution. I am not quite sure, that I understood the behavior of population the controls with data, that you attempt to implement. You mentioned, that there are 3 RadComboBox, which population with data depends on the previous ones. But, I noticed that there are 6 different RadComboBoxes. Would clarify a bit more on your scenario?

Regards,
Nencho
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
Stargazer
Top achievements
Rank 2
answered on 09 Jul 2013, 08:36 AM
Hello Nencho!

Thanks for the reply. Sure I can elaborate a bit more on my scenario. In fact there are more than 3 combos. There are several groups of 3, which deal with the almost the same info. The data on them is something like this:

- District
- Municipality
- City / Village

This data is related like so:

District has 1 or more Municipalities;
Municipality has 1 or more Cities or Villages

A person has to have a District, a Municipality and a City or Village.

This info is related to the address of the people and also the place where they were born. Maybe I made myself a bit more clear now. :)

So, for simplicity sake, I mentioned only 3 since the issue is common on all "groups" of combos which deal with this info.

The District combos are the only one that get's populated first hand. No problems here. The Municipalities combo get's populated only when a district is selected. Same thing applies to the Cities combo, when a Municipality is selected.

This all goes well when I simply need to select values. My problem is that there are 4 people on this:

-Student;
-Father;
-Mother;
-Person responsible for the student on all matters related to schooling;

My app MUST let users click a button (the already mentioned one) so they can copy the information from any one of those people to the person responsible. This is needed because this information may change on a yearly basis and must be stored for historic reasons.

So, My question is how to do just that, client side, with related combos like this ones. :)

Thanks and Regards!
Nuno
0
Nencho
Telerik team
answered on 11 Jul 2013, 03:04 PM
Hello Nuno,

Thank you for the clarification. However, I would like to clear one more thing on your scenario. You mentioned that you have a button to copy the data. You you provide us with the logic, implementation for achieve this scenario. Or is it the previously provided code snippet, which demonstrates the implementation in the mentioned button Click handler?

Regards,
Nencho
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
Stargazer
Top achievements
Rank 2
answered on 11 Jul 2013, 05:38 PM
Hello Nencho.

In fact, the previously provided snippet had the purpose to show you the code I'm using to try and copy the values. Any way, here goes a new snippet, a bit more complete:

// Copy data from source controls
//Get a reference to source controls
(... here are all textboxes. Irrelevant for now ...)
cmbDistrictPai = $find("<%= cmbDistrictPai.ClientID %>");
cmbMunicipalityPai = $find("<%= cmbMunicipalityPai.ClientID %>");
cmbCityVillagePai = $find("<%= cmbCityVillagePai.ClientID %>");
 
// Get a reference to destination controls
(... here are all textboxes. Irrelevant for now ...)
cmbDistrictEE = $find("<%= cmbDistrictEndEdu.ClientID %>");
cmbMunicipalityEE = $find("<%= cmbMunicipalityEncEdu.ClientID %>");
cmbCityVillageEE = $find("<%= cmbCityVillageEncEdu.ClientID %>");
 
// Copying data
(...)
cmbDistrictEE.trackChanges();
cmbDistrictEE.get_items().getItem(cmbDistrictPai.get_selectedIndex()).select();
var item = cmbDistrictEE.get_items().getItem(cmbDistrictPai.get_selectedIndex());
cmbDistrictEE.commitChanges();
cmbMunicipalityEE.requestItems(item.get_value(), false);
                        
cmbMunicipalityEE.trackChanges();
cmbMunicipalityEE.get_items().getItem(cmbMunicipalityPai.get_selectedIndex()).select();
item = cmbMunicipalityEE.get_items().getItem(cmbMunicipalityPai.get_selectedIndex());
cmbMunicipalityEE.commitChanges();
cmbCityVillageEE.requestItems(item.get_value(), false);
 
cmbCityVillageEE.trackChanges();
cmbCityVillageEE.get_items().getItem(cmbCityVillagePai.get_selectedIndex()).select();
item = cmbCityVillageEE.get_items().getItem(cmbCityVillagePai.get_selectedIndex());
cmbCityVillageEE.commitChanges();

All the combos, except the ones containing districts are loaded using load on demand, via RequestItems event.

Best regards!
0
Stargazer
Top achievements
Rank 2
answered on 16 Jul 2013, 09:19 AM
Hello!

I'm wondering if no one else out there has the same issue... The only solution that comes to mind now is remake the all thing to use another approach (server side operations) which kinds of sucks, since there are times where none of the inputs live in the server yet. :(

No one has any ideas to help me?

Thanks to all! :)
0
Nencho
Telerik team
answered on 16 Jul 2013, 12:57 PM
Hello Nuno,

I would suggest you a slightly different approach, than inserting a new item in the desired RadComboBoxes. I would suggest you to alter the Text and Value of the desired RadComboBoxes. I have prepared a sample page for you, implementing the above suggestion. In addition, here is a video, demonstrating the behavior at my end. Please give it a try at your end, and let me know if I had missed something.


Regards,
Nencho
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
Stargazer
Top achievements
Rank 2
answered on 16 Jul 2013, 01:31 PM
Hello Nencho!

Thanks on the update! In fact, this approach seems cleaner than the one I was using right now. I ended up simplifying my code, using OnClientItremsRequested event to select the correct item on each combo. It was kind of working, but I try the approach you recommend. I'll then let you know the results.

Regards,
Nuno
0
Stargazer
Top achievements
Rank 2
answered on 17 Jul 2013, 09:30 AM
Hello Nencho and all!

I manage to put it to work adjusting my inicial approach, by setting the selected item in the event OnClientItemsRequested of the "target" combo.

Your approach would probably work too, but It would take me more time to change everything than it took to use OnClientItemsRequested. :)

Example dumy code on:
function cmbCityVillageEncEdu_ClientItemsRequested(sender, eventArgs) {
    if (copyingData) {
        var sourceCombo = null;
 
        switch (origemDados) {
            case 'pai':
                sourceCombo = $find("<%= cmbFreguesiaPai.ClientID %>");
                break;
 
            case 'mae':
                sourceCombo = $find("<%= cmbFreguesiaMae.ClientID %>");
                break;
 
            case 'proprio':
                sourceCombo = $find("<%= cmbFreguesiaAluno.ClientID %>");
                break;
        }
        var cmbFreguesiaEE = sender; //$find("<%= cmbFreguesiaEncEdu.ClientID %>");
 
        cmbFreguesiaEE.trackChanges();
        if (sourceCombo != null) {
            cmbFreguesiaEE.findItemByValue(sourceCombo.get_value()).select();
 
            copyingDados = false;
            origemDados = '';
        }
        cmbFreguesiaEE.commitChanges();
        sourceCombo = null;
    }
}

The other code stayed basically the same, but a bit more trimmed since I removed superfluous code.

Thanks for all the help, even though I didn't use your code suggestion, it set me in the right direction. ;)

Regards!
0
Nencho
Telerik team
answered on 18 Jul 2013, 12:59 PM
Hello Nuno,

Thank you for sharing your solution with the community.

Regards,
Nencho
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
Stargazer
Top achievements
Rank 2
answered on 18 Jul 2013, 02:34 PM
Hi Nencho.

No problem. :) 

Regards,
Nuno
Tags
ComboBox
Asked by
Stargazer
Top achievements
Rank 2
Answers by
Nencho
Telerik team
Stargazer
Top achievements
Rank 2
Share this question
or