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

Is there a way to know which subform button was clicked?

Avatar

Level 7

Hi,

This has always bugged me.

Is there a simple way to know when i click a button in a subform which subform instance of the button was clicked?

What i mean is like: if this clicked button is on instance 3 of the subform then do something related to instance 3.

I am close to completing a form but an oversight created more issues and knowing which instance is being clicked would mean i could continue working the same way, or if i have to try something different.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Well, xfa.context points to an object, so you can also use scripting methods you would use for fields or subforms.

Given you have a repeatable table row with a button and want to show a message onle when the button in a specific instance of the row is clicked, the script would look like:

form1.#subform[0].Table1.Row.Button::click - (JavaScript, client)

// xfa-context = form1.#subform[0].Table1[0].Row[n].Button

// xfa-context.parent = form1.#subform[0].Table1[0].Row[n]

if (xfa.context.parent.index === 2) {

xfa.host.messageBox("The third button was clicked!");

}

View solution in original post

6 Replies

Avatar

Level 10

Hi,

When you reference a form object by name in your code it will try and match it against the siblings, then it will work it's way up the form structure until it matches an object of that name.

So, if your parent subform is called something like Row1, this in the button click event which can be in as many subforms below Row1 you can use Row1.index to return instance number, it is zero based so the third instance will return 2.

Is that what you were after?

Regards

Bruce

Avatar

Level 10

You also can use the undocumented xfa.context object to identify what botton was clicked.

xfa.host.messageBox("The button '" + xfa.context.name + "' (" + xfa.context.somExpression + ") was clicked.");

Avatar

Level 7

Not quite what i was after, but did give me an idea for something else. I have been able to look at my form in a different way and have decided to go another direction without needing to identify the button being clicked.

Avatar

Level 7

Almost. This helps me to know which button is clicked

What i am trying to work out is something like this (i know this isnt correct but am trying to help visualise it:

if(blahblah.Row1[2].Button1.isClicked)

{

//do something specific because the third instance of Button1 was clicked.

}

1511139_pastedImage_0.png

Avatar

Correct answer by
Level 10

Well, xfa.context points to an object, so you can also use scripting methods you would use for fields or subforms.

Given you have a repeatable table row with a button and want to show a message onle when the button in a specific instance of the row is clicked, the script would look like:

form1.#subform[0].Table1.Row.Button::click - (JavaScript, client)

// xfa-context = form1.#subform[0].Table1[0].Row[n].Button

// xfa-context.parent = form1.#subform[0].Table1[0].Row[n]

if (xfa.context.parent.index === 2) {

xfa.host.messageBox("The third button was clicked!");

}