Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Button makes subform visible, then adds another instance

Avatar

Level 7

Hello,

I have a button which makes a subform visible. That is working fine.

I'd like the button when clicked a second time to add another instance of the same subform. Is this possible? I have no idea how to begin with the JavaScript for this and would appreciate help.

Thanks in advance,

MDawn

1 Accepted Solution

Avatar

Correct answer by
Level 10

Instead of making the subform visible and then adding instances you can do it just using instances then the button is doing the same thing.

To "hide" the subform using instances, make sure under Binding that the Min Count is clicked off and the Inititial Count is set to 0 (zero) - your subform will now be hidden by default.

Change the code you have showing the subform to use addInstance() instead of presence, using the underscore shortcut for the Instance Manager (you have to use the underscore method because the instance doesn't exist yet):

_hiddenSubform.addInstance(true);

If you remove instances back to zero then the subform will go away again. Doing it this way also has the advantage of resetting all the data in the subform.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Instead of making the subform visible and then adding instances you can do it just using instances then the button is doing the same thing.

To "hide" the subform using instances, make sure under Binding that the Min Count is clicked off and the Inititial Count is set to 0 (zero) - your subform will now be hidden by default.

Change the code you have showing the subform to use addInstance() instead of presence, using the underscore shortcut for the Instance Manager (you have to use the underscore method because the instance doesn't exist yet):

_hiddenSubform.addInstance(true);

If you remove instances back to zero then the subform will go away again. Doing it this way also has the advantage of resetting all the data in the subform.

Avatar

Level 7

Thank you. This worked great.