6
Template Features for Designing Forms with
Repeating Sections
Often forms have sections that are very similar or identical to other sections. For example, a form may
accommodate multiple records of data. For the sake of convenience and compactness XFA provides
facilities to support reuse of sections within the form.
There are two types of reuse supported in XFA. Prototypes allow for a declaration to be incorporated by
reference at different places in the template. The prototyping mechanism allows properties and children
of the prototype to be overridden by each instance, so it can be used for components that are similar but
not exactly the same. The mechanism for prototypes is described below. By contrast the repetition
mechanism for subforms causes the subform and its content (including fields) to be replicated exactly. In
this case only the contents of fields can vary between instances. The mechanism for exact repetition is
described in
“Forms with Repeated Fields or Subforms” on page 200.
Prototypes
A form typically contains a great number of duplicated or similar objects; the same fonts, colors, borders,
etc. are used repeatedly throughout the form. Often, there are objects such as lines, rectangles, and even
whole field and draw objects repeated.
This presents an opportunity to significantly reduce the file size of a form template, by factoring out the
common aspects of the form into prototypical objects. As an additional benefit, the form designer may
easily apply sweeping change to the form template by making changes to a prototypical object and any
objects that are based upon that object will receive the changes.
Defining Prototypes
Starting with XFA 2.4 an element located anywhere in the template or in an external template can be used
as a prototype. However it is often convenient to enclose an element in a
proto
element to indicate that it
is included in the template purely for use as a prototype. Almost any XFA template element can be
enclosed within a
proto
element. When enclosed this way the enclosed element plays no part in the form
except when it is referenced by a
use
or
usehref
attribute on some other element. For example, the
following fragment defines a prototype for a field element.
Example 6.1
Defining a prototype using the proto element
<proto>
<field id="LastNameProto"
name="LastName"
anchorType="middleLeft">
<ui>
<textEdit multiLine="0"/>
</ui>
</font>
</proto>
Even though the field is fully specified, it will never be directly visible or accessible to a form filling user, nor
will it participate directly in
data binding.
193