I thought I would point-out a nice improvement that was made to XFA <subform> elements back in XFA 2.8: The addition of the access property.
In days of yore, if you wanted to disable all fields and exclusion groups (for the sake of brevity, I’ll refer to these collectively as “fields” in this article) in a particular section of your form, you would’ve had to write a script that recursively drilled down into all children of that section looking for fields to disable. This is because the access attribute only applied to fields.
With this change, assuming the section in question is contained within a subform, you can now easily disable all fields contained within it simply by setting the subform‘s access attribute to “readOnly”!
The following table describes the four levels of restrictiveness (in XFA 2.8, from the highest level to the lowest) that can be imposed on fields using the access attribute, either directly on a field or by a parent subform:
||Value can be loaded and calculations performed only upon form initialization.|
||The user cannot change the value directly and the field does not participate in the tabbing sequence. The field does not generate any events.|
||While the user may not change the value directly, it may be altered via scripts. The field still participates in the tabbing sequence and all events are generated except those related to direct user interaction.|
||The field is fully interactive and responds to direct user interaction.|
When a subform imposes restrictions on the fields it contains (meaning all fields within any level of nesting, not just immediate children), the inheritance on child fields and subforms follows that of the most restrictive parent imposition. For example, if a subform imposes access=”protected” and a child subform has access=”readOnly”, all of the inner subform’s children, including the inner subform itself, will effectively have a “protected” access level.
The explanations of the various access types in the table above are summarized. “Access Restrictions” on page 48 of the XFA 2.8 specification has more precise, albeit more technical, explanations of each level of restrictiveness.
Setting Access by Script
// set access level to read-only: FormObject.access = "readOnly";
If you wanted to disable all fields in the entire form with a single line of script, you would simply set the root subform’s access attribute to something other than “open”, as appropriate:
// if the root subform's name is "form1": xfa.form.form1.access = "nonInteractive"
Posted by Stefan Cameron on March 8th, 2010
Filed under Scripting,Tutorials,XFA
Both comments and pings are currently closed.