Avatar

Level 10

One way is to use instances instead of hiding - if you set the subform instances to zero basically everything inside the subform ceases to exist so mandatory problems will go away. This will reset any data in the subform as well so isn't good if you want to retain data in the subform.

Set the subform as repeatable with a Min Count of zero and then you can use setInstances() to control the visibility. You need to use the underscore prefix for the Instance Manager so you can access items that don't exist yet (if it's instances are set to zero):

_Subform1.setInstances(1); //show subform

_Subform1.setInstances(0); //hide subform

Another way is to use a script to loop recursively through subforms to change the mandatory settings before or after hiding. The following are a couple of scripts I've used in Script Objects and call when needed:

//set fields mandatory

function mandatoryYes(vNode) {

    if (vNode.className === "field") {

        vNode.mandatory = "error";

    }

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

        mandatoryYes(vNode.nodes.item(i));

    }

}

//pass subform to operate on, xfa.form will do the whole form

mandatoryYes(xfa.form);

//set fields not mandatory

function mandatoryNo(vNode) {

    if (vNode.className === "field") {

        vNode.mandatory = "disabled";

    }

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

        mandatoryNo(vNode.nodes.item(i));

    }

}

//pass subform to operate on

mandatoryNo(xfa.form);