In Microsoft Office InfoPath, you can use conditional formatting to specify different formatting options for a control that is based on conditions that occur on the form. If the specified conditions are true when a user fills out a form that is based on your form template, the conditional formatting is applied.
This article explains how to use conditional formatting to show or hide a row in a repeating table or repeating section, depending on whether the data in a row matches the value of a drop-down list box control. For example, if your form template has a repeating table that contains rows of products that fall into one of three classifications (A, B, or C), you can use conditional formatting to determine which rows are displayed, based on selections that users make on the form.
Note: You can use filters to enable users to show or hide information in a form. However, because filters aren't supported for browser-compatible form template, conditional formatting is a useful alternative to filters in browser-compatible form templates.
In this article
Step 1: Add the controls
In order to complete this procedure, your form template must contain a list box and a repeating table. To add these controls, do the following:
-
On the form template, click where you want to insert a list box and a repeating table.
-
If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
-
Under Insert controls in the Controls task pane, click List Box, and then click Repeating Table.
-
When you insert a repeating table, you will be prompted for the number of columns. Leave the default value at 3, and then click OK.
-
Above the list box that you inserted on your form template, type a label that reads Filter by Type:.
-
Type column labels in the first row of the repeating table, so that the first column reads Product, the second column reads Type, and the third column reads Price.
Step 2: Specify the conditional formatting
After you add your controls to the form template, you can specify the appropriate conditional formatting.
-
Double-click the list box.
-
Click the Data tab.
-
Under List box entries, click Add.
-
In the Value box, in the Add Choice dialog box, type A, and then click OK.
-
Repeat steps 3 and 4 to add values for B, C, and D.
-
In the list of values, select D, and then click Set Default.
-
Select the repeating table on your form template, and then on the Format menu, click Conditional Formatting.
-
In the Conditional Formatting dialog box, click Add.
-
Under If this condition is true, in the first box, select the field that corresponds to the second column of the repeating table.
-
In the second box, click is not equal to.
-
In the third box, click Select a field or group.
-
In the Select a Field or Group dialog box, select the field that corresponds to the list box that you inserted on the form template, and then click OK.
Note: The condition will dynamically compare the two values.
-
Under Then apply this formatting in the Conditional Format dialog box, select the Hide this control check box.
Note: This condition now states that if the content of the second column of a repeating table row is different from what is selected in the list box, then the corresponding rows in the repeating table should be hidden.
-
To return to the form template, click OK twice.
-
Double-click the control in the second column of the repeating table.
-
Click the Data tab.
-
Type D in the Value box.
Step 3: Preview the form template
After you add conditional formatting to the form template, it is recommended that you test the changes to ensure that they are working properly.
-
To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.
Note: By default, the selection in the list box is D. You might need to scroll up in the text box to see the other values.
-
To add a few rows to the repeating table, under the repeating table, click Insert item several times.
-
For each row in the second column of the repeating table, replace the default value of D with A, B, or C.
Note: The expressions are case sensitive.
-
Change the selection in the list box. The rows in the repeating table will appear and disappear as you select different options.
No comments:
Post a Comment