Hiding sections in an InfoPath form

 I was trying to figure out how to hide sections like in a Lotus Notes form. So I came up with the following solution. The form design is displayed below:
form design

form design







I have two buttons and a section. The section contains some field labels and fields. Clicking on the Hide button will hide the section from the user. Clicking on the Display button will display the section to the user.

I added an attribute field named “hideContactSection” as a data source. The data type is defined as True/False (boolean). The default value is “0”.

Data source
Data source








The attribute field is defined in the template.xml file as follows:

<my:myFields my:hideContactSection=”0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:my=”http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-24T22:36:36” xmlns:xd=”http://schemas.microsoft.com/office/infopath/2003“>

The Hide button contains a Rule named “Hide Contact Section”. The rule sets the value of the hideContactSection attribute to “1”.

Hide section rule

Hide section rule












The Display button contains a Rule named “Display Contact Section”. The rule sets the value of the hideContactSection attribute to “0”. Both rules are defined in the manifest.xsf file.

The unbound controls section defines that rules exist for each button.

    <xsf:button name=”CTRL_Button_Hide”>
     <xsf:ruleSetAction ruleSet=”ruleSet_1″></xsf:ruleSetAction>
    <xsf:button name=”CTRL_Button_Display”>
     <xsf:ruleSetAction ruleSet=”ruleSet_2″></xsf:ruleSetAction>

The rulesSets section defines the details of each rule.

  <xsf:ruleSet name=”ruleSet_1″>
   <xsf:rule caption=”Hide Contact Section” isEnabled=”yes”>
    <xsf:assignmentAction targetField=”@my:hideContactSection” expression=”&quot;1&quot;”></xsf:assignmentAction>
  <xsf:ruleSet name=”ruleSet_2″>
   <xsf:rule caption=”Display Contact Section” isEnabled=”yes”>
    <xsf:assignmentAction targetField=”@my:hideContactSection” expression=”&quot;0&quot;”></xsf:assignmentAction>

The section has a conditional format defined in the section properties tab. The section is hidden from the user when the hideContactSection attribute has a value of “1”.

Conditional format for section

Conditional format for section









The details of the conditional format is stored in the view1.xsl file. An xsl:if statement tests the value of the hideContactSection attribute to determine if the section should be displayed or not.

 <xsl:template match=”my:ContactSection” mode=”_2″>
  <xsl:if test=”not((../@my:hideContactSection = &quot;1&quot;))”>

I am using buttons in this example because it is easier to understand. I could change how the attribute value is set. Or I could use a different conditional format option. But this seems like a good place to start.

4 thoughts on “Hiding sections in an InfoPath form

  1. Great site this rhrempel.wordpress.com and I am really pleased to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor 🙂

    • I have not tried this. I have seen quite a few posts on other blogs; but none with simple solutions. I suspect most developers go with the out-of-the-box feature.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s