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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

Reset Dynamic Form with multiple tables

Avatar

Level 2

I have a form to build flowable dynamic lesson plans for training.  Each lesson plan form consists of multiple pages, some of the pages contain multiple subforms, several having dynamic table rows.  I am attempting to place a single reset form button on the page to clear all field values and reset all table row instances to 1 by clicking a button on the form master page. 

My Current XFA/javascript attempt is below;

LP.#pageSet[0].Pt1.sFrmPfHd.resetForm::click - (JavaScript, client)
  xfa.host.resetData();
//  xfa.host.remerge(); <- didn't work
// loop through table and delete rows
while (LP.Pg1.FlowContentPg1.rowSFrmTngMethodPick.tblData._rowSubform.count > 1)
{
  LP.Pg1.FlowContentPg1.rowSFrmTngMethodPick.tblData._rowSubform.removeInstance(0);
}
while (LP.Pg1.FlowContentPg1.rowSFrmTngMethodsFree.tblData._rowSubform.count > 1)
{
  LP.Pg1.FlowContentPg1.rowSFrmTngMethodsFree.tblData._rowSubform.removeInstance(0);
}
while (LP.Pg3.PgBody.rowSFrmTngMethodPick.tblData._rowSubform.count > 1)
{
  LP.Pg3.PgBody.rowSFrmTngMethodPick.tblData._rowSubform.removeInstance(0);
}
while (LP.Pg3.PgBody.rowSFrmTngMethodsFree.tblData._rowSubform.count > 1)
{
  LP.Pg3.PgBody.rowSFrmTngMethodsFree.tblData._rowSubform.removeInstance(0);
}
while (LP.Pg3.PgBody.rowSFrmLP.tblData._rowSubform.count > 1)
{
  LP.Pg3.PgBody.rowSFrmLP.tblData._rowSubform.removeInstance(0);
}

I would attach the form but cannot seem to find that as an option.  If you would like to see  the actual form please email me.

mailto:toby.yadon@us.af.mil

1 Accepted Solution

Avatar

Correct answer by
Level 10

This should do the trick.

// Reset subforms to inital number of occurences

function resetSubforms (oNode) {

    if (oNode.className === "subform") {

    if (oNode.instanceManager !== null) {

    var iCount = oNode.instanceManager.count,

    iMin = oNode.occur.min ? oNode.occur.min : 1,

    iInit = oNode.occur.initial ? oNode.occur.initial : iMin;

    if (iCount > iInit) {

    oNode.instanceManager.setInstances(iInit);

    }

    }

    }

    for (var i = 0; i < oNode.nodes.length; i += 1) {

        resetSubforms (oNode.nodes.item(i));

    }

}

resetSubforms (xfa.form); // call the function

View solution in original post

3 Replies

Avatar

Level 10

You should use the setInstances() method first to reset the table to the desired amount of rows.

Then use the resetData() method.

// Reset tables

LP.Pg1.FlowContentPg1.rowSFrmTngMethodPick.tblData._rowSubform.setInstances(1);

LP.Pg1.FlowContentPg1.rowSFrmTngMethodsFree.tblData._rowSubform.setInstances(1);

// reset data

xfa.host.resetData();

Avatar

Level 2

I tried your suggestion and was unable to make it work.  I may not be addressing the dynamic node addresses quite the way I need to.  Would it be possible to write a generic loop to loop through the node tree and reset all setInstances(1) without having to specify them individually?  This would also make the function usefule in a multitude of forms...

Thank you for your time.

Avatar

Correct answer by
Level 10

This should do the trick.

// Reset subforms to inital number of occurences

function resetSubforms (oNode) {

    if (oNode.className === "subform") {

    if (oNode.instanceManager !== null) {

    var iCount = oNode.instanceManager.count,

    iMin = oNode.occur.min ? oNode.occur.min : 1,

    iInit = oNode.occur.initial ? oNode.occur.initial : iMin;

    if (iCount > iInit) {

    oNode.instanceManager.setInstances(iInit);

    }

    }

    }

    for (var i = 0; i < oNode.nodes.length; i += 1) {

        resetSubforms (oNode.nodes.item(i));

    }

}

resetSubforms (xfa.form); // call the function