views:

35

answers:

3

What I am doing might be really stupid, if so, please correct me, but I am trying to do the following thing:

I want to have a list with (for example) the following items:

List Addresses

-Name
-Address
-City
-Country

But, based on their Country, I want to display different columns that I want to record in a List. For instance:

CountryColumns

(United States - SSN - Yes)
(United States - State - Yes)
(United States - Province - No)
(United Kingdom - SSN - No)
(United Kingdom - State - No)
(United Kingdom - Province - Yes)

And then when the user picks United States in the country list, the next time the user edits his information, certain columns will be shown. (It's also possible that all will be shown, and that the next time the columns with No will be hidden).

I've looked at ways to do this, and I only found out that Infopath is able to do this. But, that'd mean I would have to create a different view for every country, and show / hide certain columns. It seems like that is a bit of overkill.

Anyone knows a way how to do this?

Greetings,

Mats

A: 

You cannot do this out of the box.

Tom Vervoort
So, how would I go and do this via some programmable solution? I really don't mind developing webparts or custom lists, for whatever that is worth. It would really help if I could just get this done 'in a way
Mats Willemsen
Well there are a couple of options. The easiest one is to create a custom webpart to input/update your listitems. That way you have complete control over the way things are rendered. You could also replace the new/edit forms of the list, a google search can help you get started.
Tom Vervoort
+1  A: 

There are four ways you could modify SharePoint to do this that come to mind.

  1. Have a list address content type and then a separate content type for each country that requires extra fields. Use a webpart to enter data to the list using the correct country's content type.

  2. Same as above but instead of entering data through a web part, you can add the data into the list using the base address content type. Use an item adding event receiver to decide which content type to add the data to.

  3. Use one super content type that includes all fields but with custom list view pages to filter the fields based on the county value.

  4. Use infopath with either separate views for each country or a section for each special field with a condition to hide it if the required country isn't selected.

Personally I would recommend 4. It's the simplest and quickest to implement.

Dan Revell
+1  A: 

Here are three options:

  1. Custom content types. This is probably the most SharePoint-y way to do it. You can create a content type for each Country and then control which fields are included in that content type. The obvious downsides to this are that you could end up creating a lot of content types and also that selecting a content type (especially when creating a new item) is not the same as selecting a choice from a dropdown list.
  2. Javascript/jQuery. Either by changing your master page or by adding a Content Editor Web Part to your Edit Form, you could use javascript to hide certain fields based on the selected value of Country.
  3. Custom fields. This is the most involved, but instead of having the SSN field be a regular Single Line of Text field, you could create a custom field that inherits from SPFieldText and then manages its render visibility based on the selected value of Country.
Rich Bennema
The first one seems to be the way to go. Since then I can just keep the same UI, and the same lists, and I can even reuse it all. I didn't even know adding two different content types to one list is possible but this is great! I am going to try it out, and post the results here.!
Mats Willemsen
To save reproducing columns in each content type, figure out which columns are "core". By that I mean the columns that are required regardless of the country. Build a content type to contain these. When you create further country specific content types tell them to inherit from your "core" one. This means they will have all your basic columns right off the bat. This has many advantages. In particular if you need to add extra address columns later on, you can do so to the "core" content type and then all the child country content types can automatically get the new columns too.
Dan Revell