Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Add Button

Avatar

Former Community Member

Hello,

I have created a subform that I would like to be hidden and when the add button is clicked the form will appear, then the user can click the add button as many times for the subform to appear as many times as necessary.

currently the add button works if i have the subform visible. however, as soon as i changed the subform to 'hidden' the add button does not work.

i tried adding code in the click event to make the subform visible when the button is clicked, however this is not working.

does anyone know another way around this?

thanks in advance,

Nik

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Try a regular button with this in the click event:

form1._subfrmChildren1.addInstance(true);

This is on the basis that the name of the repeating subform is "subfrmChildren1" and that it is directly beneath "form1" in the hierarchy.

Niall

View solution in original post

6 Replies

Avatar

Level 10

Hi Nik,

Best approach is to select the subform and go to the Object > Binding palette. There, deselect the Min Count. This way the form will start off with no subform. The Add button will then work.

However please note that in your script if you are using "instanceManager", you will need to replace it with the shorthand underscore, as instanceManager will not work when there isn't an instance of the repeating object on the form.

For example:

page1._Subform1.addInstance(true);

Hope that helps,

Niall

Avatar

Former Community Member

Thanks Niall,

I have tried to remove the minimum however i cannot find anything that says addInstance.

I am using the generic Add button from the object library. this is the code that is under the click event:

 

/* This button will Add one instance of the repeating subform or table row.

 

sSubformSOM: SOM expression of the repeating subform or table row.

bCalc: Flag - true if the new instance might be referenced by other calculations, otherwise false.

message: The error message displayed.

These variables must be assigned for this script to run correctly.

 

Replace <value> with the correct value.

 

*/ 

var sSubformSOM = " form1.subfrmChildren1";     // Example: var sSubformSOM = "xfa.form.form1.Subform1";

var bCalc = true;              // Example: var bCalc = false;

var message = "You have reached the maximum number of items allowed.";

// DO NOT MODIFY THE CODE BEYOND THIS POINT - 8.2.1.3158.1.475346.466429 - Subform_Instance_Controls_Add.xfo

// Build the SOM expression of the Instance Manager using the 'underscore' syntax.

var oSubform = xfa.resolveNode(sSubformSOM);         // Evaluate the SOM expression.

var sParentSOM = oSubform.parent.somExpression;      // Get the parent SOM expression.

var sManagerSOM = sParentSOM + "._" + oSubform.name; // Build the SOM expression of the Instance Manager.

var oManager = xfa.resolveNode(sManagerSOM);         // Evaluate the SOM expression.

var nMaxCount = oManager.occur.max;     // Get the maximum number of subform occurrences allowed.

var nSubCount = oManager.count;         // Get the current number of instances.

// Proceed if the maximum number of subform occurrences has not been reached.

if ((nMaxCount == "-1") || (nSubCount < nMaxCount)) {

   

    // Invoke the Instance Manager.

    var oNewInstance = oManager.addInstance(1);

    // Fire the form calculations.

    if (bCalc == true) {

       

        // Execute all the form calculations.

        xfa.form.recalculate(1);

    }

} else {

    xfa.host.messageBox(message,"Add Item", 3);

}

// END OF DO NOT MODIFY

Avatar

Level 10

Hi Nik,

That script should work, as the underscore is in this line:

var sManagerSOM = sParentSOM + "._" + oSubform.name;

Give it a try,

Niall

Avatar

Former Community Member

I have tried it with this and it does not work...

Avatar

Correct answer by
Level 10

Hi,

Try a regular button with this in the click event:

form1._subfrmChildren1.addInstance(true);

This is on the basis that the name of the repeating subform is "subfrmChildren1" and that it is directly beneath "form1" in the hierarchy.

Niall