Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Change event of dropdown not working in new instance.

Avatar

Level 3

Hello

I have a table which contains a dropdown, and on the change event of the dropdown it shows and hides various sub forms depending on the selection.  The row in which this dropdown lives is repeatable.  The first dropdown does as its told, but the second and subsequent ones do not - and I know it is because I am not referencing it correctly and it is looking at the first instance only.  I have honestly scoured for hours on this one, but I get confused between [*], _subform, [0], resolveNodes, resolveNode etc.

Is anyone able to explain to me in simple terms how to reference the dropdown / subforms so it executes the change event in all instances?   Or how to reference a repeating object in general?

Thank you so much,

Nat

6 Replies

Avatar

Level 10

Hi Nat,

The best way to generate a reference to the subforms you are trying to hide is to follow these steps

  • make sure the focus is in the script window
  • hold down the ctrl key and hover over a field in the design surface
  • you should notice the cursor changing to a "v"
  • click the field and the reference will be generated in the script window.

You will have to remove the field reference at the end to get the subform reference.

Hopefully seeing how the reference are generated will help make things a bit clearer.

Basically in a repeat all your references to other fields in the same repeat need to be relative, so should use any [*] or [0] references

Bruce

Avatar

Level 3

I think this whole referencing business is going to kill me.  I  have to travel interstate next week and I have downloaded a truckload of You Tube clips on it to watch on the plane try and wrap my brain around it!! 

I have the reference of the subforms ok -  what I can't manage is to reference the repeats...and I did try the [*] but I have probably put it in the wrong spot.  This is what I have:

Repeating row that contains the dropdown is:    Main.tblPartV.Row1

The dropdown has selections (will only name a couple) "Company"  "Individual"   "Joint"

sfAccount contains tblCompany, tblIndividual and tblJoint tables that should turn on and off as per the selection from the dropdown

So my "add row" button not only adds a row to tblPartV (and subsequently another dropdown) it (should) also add a separate instance of either Individual, Joint or Company.  The instances add fine, but it the dd doesn't work because my change event just has:

if ($.boundItem(xfa.event.newText) == Company) {

xfa.resolveNode("sfAccount.tblCompany").presence = visible;

xfa.resolveNode("sfAccount.tblIndividual").presence = hidden;

etc.

it doesn't know where the repeats are - is that just putting the [*] at the end of say, tblCompany[*]?

Sorry I know I am thick - I really will set aside my whole trip to try and get this straight!!!!

Avatar

Level 10

I'm not sure I'm following, is sfAccount under Row1 or is this another table later in the form?

If you can upload your form somewhere like google docs and add a link to this thread we can have a look.

Avatar

Level 3

Fair enough - I think I'm just over this one   We are blocked from anything Google or DropBox-like here I work for a global firm and they are very strict on that stuff.  I'll try and explain better but if it still doesn't make sense, don't worry - I might just find another way to do it!

Table with repeating row is within Main.  So Main.tblPartV.Row1  It also has an account number field within that row and a dropdown (ddType) which holds the selections "Individual, Company, Joint" etc.

Further down the page is a subform called sfAccount (so Main.sfAccount) and along with an account number field (which is visible) it contains 5 hidden tables (Individual, Company, Joint etc).  These hidden tables will show or hide depending on  the selection from ddType back up in tblPartV.  For the first line, all works well.

When the "add row" button is clicked up in tblPartV, it not only adds another row to the table (so a new ddType will appear),  it also adds another instance of sfAccount further down.  The account number for each line in tblPartV is replicated via the exit event to the new instances of the sfAccount account number fields but when I try and select a change in the new ddType in the new row created in tbPartV , no new table is shown in sf Account - I just see the new instance of sfAccount , the account number - but no table.

So I just need to tell the new instance of ddType to look at the new instances of all the tables - and show them when they are supposed to!

Even writing that exhausted me....too hard for a Friday arvo, right?

Avatar

Level 2

Hi, so basically what you need is to check the instance number of your Main.tblPartV.Row1 and then reference your Main.sfAccount with that number using resolveNode. Your key to this is .instanceIndex. So if your ddType is located under the Main.tblPartV.Row1, your code will look something like this:

var row_counter = this.parent.instanceIndex

var ddType_selection = this.rawValue

if (ddType_selection == "Individual"){

xfa.resolveNode("Main.sfAccount[" + row_counter + "].Individual").presence = "visible"

}else if (ddType_selection == "Company"){

xfa.resolveNode("Main.sfAccount[" + row_counter + "].Company").presence = "visible"

}

and so on. This code may be not perfect syntaxically, but should give you an idea to follow.

Hope it helps.

Avatar

Level 3

Thank you so much, I will try this tomorrow. I don't think I'll ever get this.

Can you recommended a good reference for a total novice? I really want to understand this...