"Mirroring" allows you to copy data between form items, such as two fields. This means that both items will always contain the same value. Generally, this is most useful in forms with multiple pages that use common data.
For example, you may have a form that requires the user to provide their address on page one and page three. Instead of forcing them to re-type their address on each page, you can simply set up the form to copy their address from page one to page three. This is particularly useful for wizard-style forms, as it allows you to collect user data using simple wizard-style pages, and have the corresponding sections in the final traditional-style page automatically update with this information.
Note: When you mirror data, the user can still change the information in the item that contains the copy of the data. For example, once the user’s address was copied to page three, the user could then move on to page three and type in a completely different address. Unfortunately, doing this will destroy the compute you added to share the data from the original item to the copy. To prevent this problem, always make your mirrors read-only. This will prevent the user from changing the data and ruining your computes.
XFDL example
In XFDL, there are two ways to mirror data. The first is a simple reference, where the page, item, and option that contain the data you want to mirror are placed in a compute contained in the option you want to share the data with. For example, if you wanted to collect the value of the first name field on page 1 and copy it to the value option of the first name field on another page, you would create the following compute:
<value compute="PAGE1.first_name_field.value"></value>
The second method is dereferencing. When you dereference an item or option, you tell the compute to find the form element identified by a reference. In other words, if an option had a literal value that contained a reference, and you wanted to know what the value of the reference was, you would use a compute with a dereference to retrieve it. You would primarily use a dereference to find the value of a cell in a popup or list. For example, the value of a list depends upon which list choice the user selected. Therefore, to discover the value of a list, you must first determine which cell was selected and then determine the value of the cell.
The following code sample shows a simple compute with a dereference:
<value compute="PAGE1.occupation_list.value-value"></value>
XForms example
In XForms, you can mirror data by having two items reference the same node in the data model. For example, to copy a user’s first name from a field on page 1 to a field on page 3, both fields must contain an XPath reference to the "first_name" node. The first code sample below shows a sample XForms instance that contains a "first_name" node. The second sample shows two pages, both containing fields that reference the "first_name" node.
XForms instance that contains the "first_name" node:
<xforms:instance xmlns="" id="Name">
<full_name>
<first_name></first_name>
<last_name></last_name>
<middle_name_1></middle_name_1>
<middle_name_2></middle_name_2>
</full_name>
</xforms:instance>
XForms items that reference the "first_name" node:
<page sid="PAGE1">
<global sid="global">
<label>PAGE1</label>
</global>
<field sid="FirstName">
<xforms:input ref="instance('Name')/first_name">
<xforms:label>First Name</xforms:label>
</xforms:input>
...other options...
</field>
...other items...
</page>
<page sid="PAGE2">
<global sid="global">
<label>PAGE1</label>
</global>
<field sid="FirstName">
<xforms:input ref="instance('Name')/first_name">
<xforms:label>First Name</xforms:label>
</xforms:input>
...other options...
</field>
...other items...
</page>
Exceptions to this practice
There are no exceptions to this practice.