Issue with RequestItems on related combos

11 posts, 0 answers
  1. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 03 Jul 2013 Link to this post

    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!
  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 08 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 09 Jul 2013 Link to this post

    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
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 11 Jul 2013 Link to this post

    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.
  6. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 11 Jul 2013 Link to this post

    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!
  7. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 16 Jul 2013 Link to this post

    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! :)
  8. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 16 Jul 2013 Link to this post

    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.
  9. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 16 Jul 2013 Link to this post

    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
  10. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 17 Jul 2013 Link to this post

    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!
  11. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 18 Jul 2013 Link to this post

    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.
  12. Stargazer
    Stargazer avatar
    73 posts
    Member since:
    Jan 2007

    Posted 18 Jul 2013 Link to this post

    Hi Nencho.

    No problem. :) 

    Regards,
    Nuno
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017