Create text boxes for items selected in a multiple-selection list box in InfoPath 2010

Filed under: InfoPath 2010

Learn how you can use conditional formatting to hide and show rows of a repeating table that are based on the items selected in a multiple-selection list box on an InfoPath 2010 form.

ADVERTISEMENTS

You cannot create text boxes on an InfoPath form at runtime simply because you cannot dynamically create fields that are not already present in the Main data source of an InfoPath form and that do not adhere to the schema that was defined during design time of the InfoPath form template.

An exception to the above is if you write code to add rows to a repeating table which is already part of the schema of the InfoPath form, or write code to add items to a drop-down list box which is bound to a repeating group that is already part of the Main or a secondary data source.

However, you can pre-add text boxes, hide them, and then use conditional formatting to show them when you require them. So let’s look at how you can go about doing this.

Suppose you have a multiple-selection list box on an InfoPath form that contains 5 items: 1=Last Name, 2=First Name, 3=Street, 4=City, 5=Country.

Multiple-selection list box with 5 static items in InfoPath 2010

Figure 1. Multiple-selection list box with 5 static items in InfoPath 2010.

Suppose now that you want to have a text box appear corresponding to any of these items whenever an item is selected from the multiple-selection list box.

You can use a repeating table that is prefilled with 5 rows, with each row containing a label and a text box corresponding to one of the selected items. And you can use a hidden column in the repeating table to keep track of which row pertains to which item in the multi-select list box.

And did you know that you can format a repeating table to be completely invisible on an InfoPath form? Here is how you do it:

  1. Add a Repeating Table control with 3 columns to the InfoPath form template.
  2. Right-click the first text box and select Change Control > Calculated Value.
  3. Click the repeating table to select it, and then click Data > Form Data > Default Values.
  4. On the Edit Default Values dialog box, expand group2, add 4 group3 nodes, and fill field2 and field4 of each group3 with the corresponding display name and value of an item in the multiple-selection list box, and click OK.
  5. Right-click the repeating table and select Repeating Table Properties.
  6. On the Repeating Table Properties dialog box, deselect the Allow users to insert and delete rows check box, and click OK.
  7. Right-click the third column of the repeating table (containing field4), and select Delete > Columns. This effectively makes this column a hidden column in the repeating table.
  8. Right-click the repeating table and select Borders and Shading.
  9. On the Borders and Shading dialog box on the Border tab, select None under Presets, select white (or any other color you are using as the background color for the view) from the Color picker, click the Shading tab, select No color, and click OK. This makes the repeating table borderless and colorless.

    Borderless repeating table in InfoPath 2010

    Figure 2. Borderless repeating table in InfoPath 2010.

  10. Now you must use conditional formatting to make the repeating table invisible. Click the repeating table to select it, and then click Home > Rules > Manage Rules.
  11. On the Rules task pane, click New > Formatting.
  12. On the Rules task pane under Condition, click None.
  13. On the Condition dialog box, select Select a field or group from the first drop-down list box.
  14. On the Select a Field or Group dialog box, expand group1, select field1 (representing the multiple-selection list box), and click OK.
  15. On the Condition dialog box, leave is equal to selected in the second drop-down list box, and select Select a field or group from the third drop-down list box.
  16. On the Select a Field or Group dialog box, expand group2, expand repeating group3, select field4 (contains a value equal to that of an item in the multiple-selection list box), and click OK.
  17. On the Condition dialog box, select The expression from the first drop-down list box, and then type not( and ) around the expression in the text box. This condition is a negation for checking the value of selected items in the multiple-selection list box. The final expression should resemble the following:

    not(../../my:group1/my:field1 = my:field4)

  18. On the Rules task pane under Formatting, select the Hide this control check box. So the final rule hides a row in the repeating table if none of the values of the selected items in the multiple-selection list box are equal to the value of field4 in that row of the repeating table.
  19. Preview the form.

When the form opens, the repeating table should be invisible, and when you select any item from the multiple-selection list box, a text box with a label should appear. Note that you could also pre-select items in the multiple-selection list box to have specific rows automatically added to the repeating table when the form opens.

The order of the text boxes remains the same as the order in which the rows where defined when you added default rows to the repeating table, and does not depend on the order in which you select items in the multi-select list box.

Text boxes for selected items in multi-select list box in InfoPath 2010
Figure 3. Text boxes for selected items in multi-select list box in InfoPath 2010.

 


Related Posts

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services