SharePoint and Infopath 2010 - Conditionally Hide Form Fields

Update: This article is now available as a video here

Some things are just easier in SharePoint 2010 than they were in earlier versions. A prime example is when you want to do anything clever with list forms.

Consider the basic list form below. This is what I'd see if I were adding a new task to my SharePoint Task List. To illustrate my example I've added two extra fields to the Task List, a Yes/No field called Special Conditions Applied (with a default of No), and a text field called Special Conditions Description. Both are highlighted in red below;

Basic SharePoint Form

My requirement for today is that the Special Conditions Description field is only shown on a new item form when the tick box for Special Conditions Applied is ticked. If there aren't any special conditions applied, why would my user want to fill that field in?

It turns out that I can meet my requirement and hide the field in less than a minute! The key to it is a certain magic button on the ribbon of the list. The purple button below 'Customize Form' will allow me to edit my New Item form in Infopath 2010, so give it a click!

Customize Form

Infopath opens and shows an edit view of my form as below. I want to change my Special Conditions Description field so I click it with the mouse and select it as below;

Infopath Form

To make the form do what I want, I'm going to add a Rule. Click Manage Rules on the ribbon within Infopath, then select New -> Formatting [rule] ;

Infopath Rule

Add a meaningful name for your rule (as it may not be the only one you do once you get started with this sort of work!). Tick the 'Hide This Control' tickbox as circled in red.

Infopath Hide Control

We don't yet have a condition for when to hide the control, so click on the 'None' link under 'Condition' above, and a new dialog will open to allow you to specify the condition as below. I want the rule to run when the 'Special Conditions Applied' field is not ticked, so I select when this is equal to FALSE, and OK the dialog;

Infopath Set Condition

That was all I needed to do for the rule. Easy huh? Now we Publish our work, and we're ready to see the result. Click the Quick Publish button on the ribbon below;

Infopath Quick Publish

We then get a notification of successful publishing;


Back in SharePoint, when creating a new item on the Task List now, I see my custom Infopath form. With the Special Conditions Applied field unticked, I see no Description field. You still see the label for the field OK, but with an extra rule you could have hidden that too - just keeping it simple! :)

Field Hidden

With the Special Conditions Applied field ticked, our user sees the Description field and can fill it in;

Field Not Hidden

The other great news about this is that although you needed Infopath 2010 on your machine to do the form change, all users of the form do not need Infopath simply to use your form. This is a webform that SharePoint is now serving, no extra software required.

This very quick introduction to Infopath 2010 Forms with SharePoint have hopefully persuaded you that your SharePoint forms can easily be made smarter than the default forms you get on lists. With a little experimentation you could quickly introduce form validation, and prefilling of field values.

Happy SharePointing!


Disclaimer: The software, source code and guidance on this website is provided "AS IS"
with no warranties of any kind. The entire risk arising out of the use or
performance of the software and source code is with you.

Any views expressed in this blog are those of the individual and may not necessarily reflect the views of any organization the individual may be affiliated with.