Expand my Community achievements bar.

Setting property for multiple objects?

Avatar

Level 2

Adobe Pro X; ES2

I need to set the access property for multiple objects based on the selection of a radio button group. I assume I have to use resolveNodes(), but cannot for the life of me get it to work. Here's what I've played with :

if (this.rawValue == "1") { 

xfa.resolveNodes("OtherCase_gp.[*]").access = "open";     

} else {  

xfa.resolveNodes("OtherCase_gp.[*]").access = "readOnly";

}

If I use Action Builder, I get endless lines of "oTargetField = this.resolveNode("OtherCase_gp.OtherCaseOther_cb"); oTargetField.access = "readOnly";" There must be a better, more efficient way to do this!

4 Replies

Avatar

Level 10

Ok,

there a many ways to do this.

Either be resolveNode or by a loop.

Here's an example with using a loop.

It will lock or unlock all fields named "OtherCaseOther_cb".

// function to lock or unlock fields

function setAccess(vNode, accessType) {

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

                    if (vNode.getAttribute("name") == "OtherCaseOther_cb") {

                              vNode.access = accessType;

                    }

    }

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

        setAccess(vNode.nodes.item(f), accessType);

    }

}

// Check the selection of the radio button group

if (this.rawValue == "1") {

          setAccess(xfa.form, "open");

} else {

          setAccess(xfa.form, "readOnly");

}

Avatar

Level 2

Thanks, radzmar - however, the fields that need to be locked based on the selection in the exclusion grp are named with different names. They do all belong to a grouping called "OtherCase_gp", and all have names that follow the format "OtherCaseXX_yy". That's why I thought the recolveNotes/wildcard combination would be handy.

Avatar

Level 10

Hi,

Here's another way to try;

var fields = xfa.resolveNodes("OtherCase_gp.#field.(name.substring(0,9) == 'OtherCase')");

for (var i = 0; i < fields.length; i++)

{

    fields.item(0).access = (this.rawValue == "1") ? "open" : "readOnly";

}

This approach will only work if your fields are all under OtherCase_gp, Radzmar's solution is more general if your form has a more complicated hierarchy.

Regards

Bruce

Avatar

Level 2

I’ll try it – thanks!

Camilla