Infopath - Advanced Design

Although Infopath designer can create most (much ?) of the User Interface, there can be times when it doesnt quite do what you need.

As an example, for drop down lists, you can pull in the values from an external data source

The dialog show the external connection and the value / display name as shown below

But what if you wanted to display both the id AND display name? The solution here is to drop into the XSL. Infopath uses XSL extensively & we can edit it if needed (Caution though, it is not as straight-forward as the normal editor & requires knowledge of XSLT). Note that the Infopath project must be saved as source files (if using Infopath.exe) or to access it in Visual Studio, close the manifest.xsf file.

By default, you will have View1.xsl - the xsl for the main view. Opening it will reveal something similar to that below, the xsl to display the drop down list and options

[code:xml]

<select class="xdComboBox xdBehavior_Select" title="" style="WIDTH: 130px" size="1" xd:binding="my:TextNode" xd:boundProp="value" value="" xd:xctname="dropdown" xd:CtrlId="CTRL1" tabIndex="0">
      <xsl:attribute name="value">
       <xsl:value-of select="my:TextNode"/>
      </xsl:attribute>
      <xsl:choose>
       <xsl:when test="function-available('xdXDocument:GetDOM')">
        <option/>
        <xsl:variable name="val" select="my:TextNode"/>
        <xsl:if test="not(xdXDocument:GetDOM(&quot;CISF_DIVISION&quot;)/dfs:myFields/dfs:dataFields/d:CISF_DIVISION[@division_id=$val] or $val='')">
         <option selected="selected">
          <xsl:attribute name="value">
           <xsl:value-of select="$val"/>
          </xsl:attribute>
          <xsl:value-of select="$val"/>
         </option>
        </xsl:if>
        <xsl:for-each select="xdXDocument:GetDOM(&quot;CISF_DIVISION&quot;)/dfs:myFields/dfs:dataFields/d:CISF_DIVISION">
         <option>
          <xsl:attribute name="value">
           <xsl:value-of select="@division_id"/>
          </xsl:attribute>
          <xsl:if test="$val=@division_id">
           <xsl:attribute name="selected">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@division"/>
         </option>
        </xsl:for-each>
       </xsl:when>
       <xsl:otherwise>
        <option>
         <xsl:value-of select="my:TextNode"/>
        </option>
       </xsl:otherwise>
      </xsl:choose>
     </select>

[/code]

 The part we are interested in is the <option></option> values...

[code:xml]

<option>
          <xsl:attribute name="value">
           <xsl:value-of select="@division_id"/>
          </xsl:attribute>
          <xsl:if test="$val=@division_id">
           <xsl:attribute name="selected">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@division"/>
</option>

[/code]

By changing this to the code below, we can show both the id and name values...

[code:xml]

<option>
          <xsl:attribute name="value">
           <xsl:value-of select="@division_id"/>
          </xsl:attribute>
          <xsl:if test="$val=@division_id">
           <xsl:attribute name="selected">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@division_id"/>
          <xsl:text> : </xsl:text>
          <xsl:value-of select="@division"/>
</option>

[/code]

This will give us the following result

UPDATE

The example above was intended for Infopaht Client. AFIK the technique 'should' work for Forms server, but a quick test based upon a comment shows that the XSL may not render correctly

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

August 7. 2010 01:19

elegant woman

what make us surprised is the worker said his rolex is fake .finally,<a href="http://www.watchestoo.com/index.php?main_page=wordpress&p=281">ulysse nardin</a>

elegant woman

August 16. 2010 19:35

vuitton bags

Easily, the post is really the greatest on this laudable topic. I concur with your conclusions and will thirstily look forward to your future updates. Saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay privy of any updates. Solid work and much success in your business enterprize!

vuitton bags

August 17. 2010 13:03

vigrx

your site layout is very good

vigrx

August 17. 2010 13:07

vigrx

your site layout is very good

vigrx

August 22. 2010 00:32

discount prada bags

You have a point. Very insightful. A nice different perspective

discount prada bags

August 26. 2010 23:12

Madeleine Hillin

I ever watched great stories about doing small time but make great time. I was surprised, so I ignored them. But it is my fault, so you must not capable and follow me to do that. When the time was changed the ecosystem will be changed too. But one can’t be changed, it is the changes itself. Why? No more to explain that. Getting the most valuable person like you is my future lucky. The best time to do that is with my brain. Offline time can be bored, so why don’t you use online time to become rich together? Vacation can be good one; especially we hope that after reaching success, time we spent can be substituted with great time for vacation. I am sure that you are capable in doing that, so great people will meet great time for spending time. Have a nice travel with chosen one. Really wonderful one!

Madeleine Hillin

August 28. 2010 00:08

Harriet Mcwilson

I was very encouraged to find this site. I wanted to thank you for this special read. I definitely savored every little bit of it and I have you bookmarked to check out new stuff you post

Harriet Mcwilson

August 29. 2010 17:05

student driver magnet

Many thanks for sharing this great write-up. Very inspiring! (as always, btw)

student driver magnet

August 30. 2010 22:06

increase semen volume

your site layout is very good

increase semen volume

August 30. 2010 22:09

increase semen volume

your site layout is very good

increase semen volume

August 31. 2010 11:04

Emma Marston

Great article! Keep up the good work :)

Emma Marston

August 31. 2010 23:56

Baby Gifts, New Baby Gifts

This is a good posting, I was wondering if I could use this write-up on my website, I will link it back to your website though. If this is a problem please let me know and I will take it down right away

Baby Gifts, New Baby Gifts

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



 

Dilbert of the day