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
Solved! Go to Solution.
Views
Replies
Total Likes
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!");
}
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.");
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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.
}
Views
Replies
Total Likes
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!");
}
Views
Replies
Total Likes
Perfect, thanks radzmar
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies