Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

17-06-2018

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
radzmar
MVP

19-06-2018

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!");

}

Answers (5)

Answers (5)

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

19-06-2018

Perfect, thanks radzmar

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

18-06-2018

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

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

18-06-2018

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

Avatar
Coach
MVP
radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
radzmar
MVP

18-06-2018

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

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

18-06-2018

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