Implementing Cascading Dropdowns in Forms Server - David Airapetyan
in

InfoPath Dev

David Airapetyan

Implementing Cascading Dropdowns in Forms Server

The InfoPath Team Blog has a great article on how to implement cascading dropdowns in InfoPath Forms Server (IPFS) without writing code: http://blogs.msdn.com/infopath/archive/2006/10/12/cascading-dropdowns-in-browser-forms.aspx. Unfortunately, this approach does not work in repeating context for the same reason Cascading Dropdowns are so hard in IPFS: there is no filtering on dropdown values.

However, if you absolutely have to have those in a repeating table or a section, there is a workaround. It is not pretty because it requires you to write code (hence the form needs admin deployment which is much harder), it pollutes your main DOM and it is less performant (postbacks are needed any time you change the "master" dropdown). However it works!

The approach relies on the fact that the data source for a dropdown can reside in the main DOM as well. Consider the following schema:

myFields
  myRepeatingTable
    myCategory
    mySubCategory

There are two dropdowns in the repeating table, one bound to myCategory and one to mySubCategory. If the values for the second dropdown come from a secondary data source, they will be the same for all rows which is obviously not desired. However, adding the source under myRepeatingTable solves the problem:

myFields
  myRepeatingTable
    myCategory
    mySubCategory
    mySubCategoryValues

Now all you need to do is to bind the second dropdown values to mySubCategoryValues and then write an OnChange handler for myCategory to modify those dynamically.

You can find a fully functional example here:

http://www.infopathdev.com/files/folders/examples/entry41178.aspx 

The zip file contains the ready-to-deploy XSN as well as the source code.

Published Aug 23 2007, 05:15 PM by davidair
Filed under: ,

Comments

 

Mark Vander Wegen said:

David,

This works fantastic. Thank you very much. However, I'm having problems implementing this to the next level. I have the following

myFields

 myRepeatingTable

   myCategory

   myType

   mySubType

   typeSource

   subtypeSource

The Type field is a drop down and is dependent on Category. And, the SubType field is also a drop down and is dependent on Type. When ever I added a field (ie subtypeSource) below typeSource things don't work correctly.

Do you have any words of wisdom for me.

September 5, 2007 6:27 AM
 

davidair said:

Hey Mark, sorry to learn that you're having problems. Technically what you are trying to do should work so probably you're just running into a small bug. Your Changed handler for myType should be re-populating the subtypeSource which theoretically should work. If you could share out your solution, maybe I could figure out what is going wrong.

September 5, 2007 11:53 PM
 

Mark Vander Wegen said:

David,

If you look at the State/City sample you have, what I'm trying to do is add County in there so it would be State/County/City.

Whenever another field is added below the repeating "Source" field the drop downs don't populate correctly. In my case if the "subtypeSource" is in the same group adn the "typeSource", then the type drop down doesn't populate. If I move the "subtypeSource" out of the same group, then the Type drop down does populate, but that has it problems also.

I would send you my whole solution but I am using SP lists for drop down values so I really can't ship it off easily.

September 7, 2007 7:38 AM
 

Mark Vander Wegen said:

David,

In the sample application I added a dummy  "countySource" below the citySource field in the data source. When you do this the City field does not populate correctly.

September 10, 2007 6:44 AM
 

someara said:

This works GREAT!!!

However, one small problem.

I am cascading a number of drop downs.  However, the program will only populate the last source item in the section.

For instance, lets say my group is called group1 and I have two source lists in it:

Group1

Source_List_1

Source_List_2

I can't get it to populate Source_List_1, it will only populate Source_List_2.

Now, if I delete Source_List_1 and reinsert it, so I get this:

Group1

Source_List_2

Source_List_1

Then Source_List_1 will populate but Source_List_2 will not.

Any clues?

February 26, 2008 11:53 AM
 

seashore67 said:

Hi David,

Is it possible to implement this solution using a Sharepoint generated XML file?  I am attempting to do a filter on a sharepoint list within a repeating table.  Every time I add a new row it only pulls the filter from the first row.  Any assistance would be greatly appreciated.

Andrew

May 2, 2008 9:36 AM
 

Frederik Van Lierde said:

Have a look at the follwing Url,  one function to use cascading dropdows within InfoPath Forms and you can add as many cascading dropdows you like

blueinfopath.blogspot.com/.../cascading-drop-downs-in-infopath-web.html

November 20, 2008 5:10 AM
 

Cascade dropdowns in a repeating field within a browser form | keyongtech said:

Pingback from  Cascade dropdowns in a repeating field within a browser form | keyongtech

January 18, 2009 9:36 AM
 

How to script drop down list box | keyongtech said:

Pingback from  How to script drop down list box | keyongtech

February 26, 2009 6:10 AM
 

Sagun said:

My problem is that I followed this one for my Purchase Request Form. When I choose the value from the first dropdownlist, it shows the desired value on the second dropdownlist . I try to use on the Repeating table.

I have Category Field and CategoryItem Field. When I select Value from the Category dropdownlist, it shows values depend upon Category dropdownlist on Item dropdownlist.

It works fine for the first row. But when I insert the second item, I was able to select the value for both Category and Item dropdown list but first value for the Item dropdownlist shows blank field. And when I try to select the value for the item dropdownlist that is blank, it shows the value for the item that I selected for the category on the second row. I don’t know, it may be due to the problem of repeating table. Please take a look on it. And If you find any solution on it, please do reply me.

May 15, 2009 11:35

May 15, 2009 12:27 PM
 

Cascading Drop downs in InfoPath Web Forms made easy « InfoPath Blog said:

Pingback from  Cascading Drop downs in InfoPath Web Forms made easy « InfoPath Blog

December 2, 2009 1:36 AM
 

Cascading Drop downs in InfoPath Web Forms made easy « Blue Oceans Associates said:

Pingback from  Cascading Drop downs in InfoPath Web Forms made easy « Blue Oceans Associates

February 11, 2010 5:12 AM
 

Mark Wilkinson said:

David,

realise this is a very old post. I'm a newbie in IPFS and have previously used cascading dropdowns outside for repeating tables successfully.

I now need to do this inside a repeating table but I need to use SP lists for the drop down values - I'm sure what you've done here can be changed, but not sure where to start.

Any pointers gratefully received

August 12, 2012 1:26 AM

About davidair

I am a Computer Science graduate from McGill University in Montreal, Canada. I have over seven years of industry experience including almost five of them spent with the Microsoft Corporation where I shipped several versions of Microsoft Office InfoPath. Originally from Russia, I am fluent in several languages, including Russian, English, French, C#, C++ and Perl. I currently reside in Montreal and work for Qdabra Software.
Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.