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 to hide a button based on a zero count of a unrelated subform?

Avatar

Level 2

I am a beginner at this. Try many different ways with no success. I found the following info in an old discussion group. There was no info to indicate that it worked. 

It is not exactly what I need. I tried to adapt it with no success.


" in the click event of the remove button should have something like this

if (this.parent.instanceManager.count > 1){

  this.parent.instanceManager.removeInstance(this.parent.index);

} else{

  xfa.resolveNode("Subform1[0].cmdRemove").presence = "hidden";

  this.parent.instanceManager.removeInstance(this.parent.index);

}

And you should have an initialize event for the subform

if (this.instanceManager.count > 1){

  xfa.resolveNode("Subform1[0].cmdRemove").presence = "visible";

} else{

  xfa.resolveNode("Subform1[0].cmdRemove").presence = "hidden";

}

I basically want to hide a button if the count of a subform get to zero. The subform has a start of zero count. If somoene decide to delete all the said subform, I need the targeted button to be "hidden". Any assistance would be much appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 2

It works as you described. Thanks

View solution in original post

4 Replies

Avatar

Level 10

I would use the indexChange event of the subform to control the presence of the desired button through a script.


MyButton.presence = this.instanceManager.count > 0 ? "visible" : "hidden";


Avatar

Level 2

This work to make the button visible as soon as you create one instance of the subform but it doesn't hide it if the user decide later to remove all the subform after having created one or more. At that point I need the button to go "hidden" and it doesn't. I am only using a testing form at this time. I have forwarded it to your email if you don' mind looking at it. Thanks

Avatar

Level 10

Ahh ok, I see what's the problem.

the indexChange event doesn't fire if there aren't any instances of an object.

So you need two separate scripts.

The first in the click event of the add button:


CmdHide.presence = "visible";


_Subform1.addInstance(1);


The second in the remove buttons click event.


CmdHide.presence = (_Subform1.count - 1) > 0 ?  "visible" : "hidden";


_Subform1.removeInstance(this.parent.index);


You can also remove the initialize event of the hide button and set it to be hidden by default in Designer.

Avatar

Correct answer by
Level 2

It works as you described. Thanks