InfoPath: Hide command text for conditionally inserting row in repeating table

By | June 2, 2010

Problem 1: Allow the users to insert a row in repeating table based on condition evaluation.

Solution:

  1. Select the repeating table, right click on it to open up context menu.
  2. Click on “Repeating Table Properties…” > “Display Tab” > “Conditional Formatting…” button. It will open up “Conditional Formatting” dialog.
  3. Click on “Add…” to open up “Conditional Format” dialog.
  4. Select the condition and check “Don’t allow user to insert or delete this control” as shown in the image below.
  5. Click OK button on every open dialog.
  6. Now preview the form. Based on evaluated condition, clicking on “Add Employee” will either allow or don’t allow you to insert a new row.

Problem 2: Above mentioned solution does not hide the command text “Add Employee” so user may try to click on it but nothing happens. The problem is to hide a command text.

Solution:

Solution requires manual xsl file editing. Follow the steps to manually change xsl to show/hide command text based on the condition.

  1. Open the form into design mode. Click on File > “Save As Source Files…” (InfoPath 2007) which will save individual source files.
  2. Open the appropriate view file in text editor. The file extension will be “.xsl”.
  3. Locate the code which shows command text. For me, it is
    <div xd:xmlToEdit="group2_1" xd:action="xCollection::insert">Add Employee</div>
  4. Now add a conditional “style” attribute to it. so the resultant code will look like
    <div xd:xmlToEdit="group2_1" tabIndex="0" xd:action="xCollection::insert">
     <xsl:attribute name="style">
     <xsl:if test="my:AllowInsertion = string(false())">DISPLAY:None;</xsl:if>
     </xsl:attribute>
    Add Employee</div>
  5. In the above code you have to change the <xsl:if> test attribute to your condition
  6. Save the file, open the form in design mode by right clicking on “manifest.xsf” file and click on “Design”.

Now when you preview the form, it will look like this

Download the example InfoPath form to hide command text for conditionally inserting row in repeating table.

4 thoughts on “InfoPath: Hide command text for conditionally inserting row in repeating table

  1. alice

    Cool!!! very simple solution. Almost i spent 6 hours for this.
    Thanks dude!!!

Leave a Reply

Your email address will not be published. Required fields are marked *