Expand my Community achievements bar.

Using drop-down to index into an array of repeatable subforms.

Avatar

Level 3

I have a drop-down and a repeatable subform. The subform has been filled with data (say name, address, phone) and repeated n times, each with different information.

I have used resolveNodes and addItem to loop through all the subforms and populate the drop-down list with all the names.

When the user selects the desired name I need to populate the nearby address and phone text objects with the info from the correct subform. Is it possible to do this using an index of the selected name to select the subform(index).address?

Thanks!

8 Replies

Avatar

Former Community Member

Each object in the repeatiung section will have a unique name to get to it. It is not enough to have just the name of the object you must include the path to it as well. In doing so the repeating subform can have an occurance number to indicate which one you want. Note that the occurance numbers are 0 based. So to reference your field it woudl be repeating_subform[occurance number].Name.rawValue. So the selectedIndex in the DDlist will give you the occurance number that you want (but it is 1 based I think). This is also assuming that the DDList will be in the same order that the repeating subforms appear. So to get the value of the Name field your expression will be:

repeating_subform_name[DDlist.selectedIndex - 1].Name.rawValue

paul

Avatar

Level 3

Thank you for the help but I seem to have trouble figuring out the best event(s) for this code. I have tried the 'change' event but since it fires on every key stroke its not the best place.

I have also tried the click event but it doesn't work like I would wish.

The drop-down may have the selection clicked or the user may enter data not in the selection list.

Would you please advise on the proper events or event to use?

Thanks!

Avatar

Level 3

I think the validate event should work well for this. I tried the following code:

   if (dropdown.selectedIndex > -1) // then a selection has been made, needed because validate event is fired before a selection

      textObject.rawValue = repeatingSubForm[dropdown.selectedIndex].object.rawValue; // dropdown.SelectedIndex is 0-based

However, I get the error message "repeatingSubForm[dropdown.selectedIndex] has no properties"

Any ideas? Thanks

Avatar

Level 3

Thanks Paul but I still have a problem...

I'm trying to use the validate event with this code: (DDlist.selectedIndex is zero-based)

   if (dropdown.selectedIndex > -1) // validate is fired before a selection is made and again after

     textObject.rawValue = repeatingSubform[DDlist.selectedindex].textObject.rawValue;

I get the error message "repeatingSubForm[DDlist.selectedIndex] has no properties"

Any ideas why?

Thanks!

 Bill

Avatar

Level 3

I solved the "no properties" problem by using a resolveNodes on the repeatable subform before referencing its objects. The code now works as I need it BUT I get a message "validation failed"!

Do I need to set a return code or something?

Thanks!

Avatar

Level 3

Solved the error message by using

event.rc = true;

All is well! Thanks again for your help!

Avatar

Former Community Member

Typically when dealing with DDLists the exit event is the best one because that indicates that the user has finished making their selection and they are ready to move on. Most people try to use the change event but that will fire each time the user makes a selction and the rawValue will NOT be set with their selection so you have to use another means to get it. On the exit event the rawValue is set so it is much easier to deal with. You should not use the validate as that event will fire on loading the form as well as any submit operation.

Hope that helps

Paul

Avatar

Level 3

As it turns out in my case the validate event is perfect. I need to perform actions depending on the user either entering data or selecting from the drop-down list.

Testing the selectedIndex to be greater than -1 tells me if a selection was made or not. It allows me to skip the first validate call and only process after a selection.

Thanks again for all your help.