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.
SOLVED

How do I use javascript or formcalc to reference child controls (not by name)

Avatar

Level 4

Hi everyone,

I've created a ton of reports in the past, and I'm now looking at creating some reusable objects so that other people can use advanced form functionality without having to learn to use scripts.

A lot of the coding was acheived using this, .parent, etc. so that they can rename controls and subforms without having to worry about breaking scripts. One issue that I am having is that Some of my code looks at children controls, and references them by name (for example, I have some code that uses setfocus to move the user to the first field in a subform).

In most languages, there are ways to refer to child controls via an indexer or an items/children array. i.e. Subform.items[0].rawValue.

I know that this would pose some issues, but I think I could sort it out, if only I knew where to start. Is there some way to reference a child control without it's name?

Thanks for your help!

- Scott

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Scott,

The subform has a nodes collection you can loop though, as you suspected.  If might show up more than you want but you can test the className to see if it is a field and then ui.oneOfChild.className to work out what type of field. So;

for (var i = 0; i < Subform1.nodes.length; i++)

{

    var n = Subform1.nodes.item(i);

    console.println(n.className + " " + n.name + " " + n.ui.oneOfChild.className);

}

Hope this helps.

Bruce

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Hi Scott,

The subform has a nodes collection you can loop though, as you suspected.  If might show up more than you want but you can test the className to see if it is a field and then ui.oneOfChild.className to work out what type of field. So;

for (var i = 0; i < Subform1.nodes.length; i++)

{

    var n = Subform1.nodes.item(i);

    console.println(n.className + " " + n.name + " " + n.ui.oneOfChild.className);

}

Hope this helps.

Bruce