Hi, Frank Mueller from the InfoPath development team here. The Multiple-Selection List Box (MSLB) control was introduced in InfoPath 2007 to enable users to select multiple items from a list when filling out forms. In this post, I will explain the different ways you can restrict and validate the data entered using this control in InfoPath 2010. I will also cover some advanced tips and tricks.
Special behavior in SharePoint List Forms
Removing Blank Default Values
First let’s look at a scenario where you may want to use the MSLB control. Say, for example, you are building a form for customers to order your company’s products. To be able to more effectively spend the company’s marketing budget in the future, the marketing department would like to know how your customers found the company’s web site. So you’ve added a Multiple-Selection List Box to gather responses to that question.
Your customers can now select one or more options. If a customer heard about the web site through a channel that is not specified in the Multiple-Selection List Box control, he/she can select the last checkbox and just type in a custom response.
The marketing department is pleased with the new order form, but many customers do not bother responding to the “How did you hear about us?” question. With InfoPath 2010, solving this problem is very easy.
In InfoPath 2010, there are two main ways that form designers can restrict and validate the data entered using the MSLB control.
New in InfoPath 2010, we can now enforce that users select at least one non-blank item by setting the “At least one selection required” property. In most cases, this is the setting that you will want to use.
When you preview the form, you will notice a red asterisk in the upper right corner of the control, indicating that a selection is required.
If you select a blank custom value, an asterisk will appear in the top right hand corner of the custom value text box.
All asterisks will disappear as soon as you select an option that is not blank, or you select the custom value text box and type in a value.
The new type of data validation is only applicable to repeating fields that are bound to Multiple-Selection List Box controls.
When setting the property at the field-level (instead of on the control), you will notice that it’s called “Non-empty occurrence required”. This is because the field can be bound to a control other than the MSLB, in which case users do not make selections when using the control.
You may set any repeating field to “Non-empty occurrence required”, but you will only see an effect when the field is bound to a Multiple-Selection List Box control. “Non-empty occurrence required” is not implemented as an XSD constraining facet, but rather as a special Validation Rule that is stored in the manifest.xsf of your form template. This has the benefit that you can set the data validation even if you are designing a form template based on a locked schema.
In most cases, the “At least one selection required” property will do you what you need to ensure that users enter the required data. In InfoPath 2010, we still support the legacy “Cannot be blank” property. When this property is set, it requires that every item that a user selects from the list has a value. It does not however require that users select an item in the first place. When you preview the form, you will notice a red asterisk, whenever you select the checkbox of the custom value text box. This indicates that if the user wants to select this option, a value has to be typed in the text box before the form can be submitted. Once you type some text in the custom value text box, the asterisk will disappear.
When a field in an InfoPath form is set to “Cannot be blank”, a minLength constraining facet is applied to the XSD element, which requires that corresponding XML nodes contain at least one character.
<xsd:element name="field1" type="my:requiredString"/> <xsd:simpleType name="requiredString"> <xsd:restriction base="xsd:string"> <xsd:minLength value="1"/> </xsd:restriction> </xsd:simpleType> This makes sense for text fields, when the form designer wants to ensure that the person filling out the form has to enter data into the field before it can be submitted for further processing. The Multiple-Selection List Box control is bound to a repeating field in the form’s data source. When the user fills out the form and makes selections in the control, a new XML node is created for each selection made. If you mark the repeating field that the control is bound to as “Cannot be blank”, InfoPath will ensure that all options selected or entered through the custom value textbox are not blank. However, if no selections are made in the control, no XML nodes are created, and hence the constraining facet of the field is not violated, and the user is not forced to make a selection.
When would I want to use “Cannot be blank” instead of “At least one selection required”?
If you want to ensure that users do not select any item that does not have a value then the “Cannot be blank” property can be used.
In the example below, both “At least one selection required” and “Cannot be blank” are set. The data is not valid because the custom selection is blank.
In the example below, only the “At least one selection required” is set. The data is valid because at least one non-blank item is selected.
In a SharePoint list, when you mark a Choice column as required, it requires users to select at least 1 item and for all selected items to have values.
Marking the field as required in SharePoint, has the same effect as setting both the “Cannot be blank” and “At least one selection required” properties in InfoPath. For consistency with SharePoint, when customizing a SharePoint list form in InfoPath 2010, only one data validation option, “Cannot be blank” is available.
When designing the order form described above, InfoPath will by default insert a blank default value node for each repeating field. As you preview the form you will notice that the custom value text box at the bottom of the Multiple-Selection List Box control will be checked by default.
If you wish there to be no default selection at all in the control, you need to remove the default value node.
Frank Mueller InfoPath Developer
Great article, Frank. I found it very helpful.
Thank you so much for this, i've been going round in circles trying to avoid a default value.
Hi, I have a problem that it seems to be impossible to solve. I'm using multiple selection forms with two infopath lists. I have the same options in those fields of the two lists. I've been trying to pass the options selected on one list to another by workflow of Datapolis. I don't know how, but the options are repeated on the destination list. I spoke with datapolis and they said me that is not they problem. The problem is on infopath. I've been searching a long time... maybe the problem is on blank default values of multiple selection fields, but I've checked it and it doesnt work... I don't know what to do... Maybe I can speak with someone from infopath or whatever... Please. Thanks in advance.
Is it possible to have ALL LOOKUP options marked by default ??
Many thanks. Solved my issue of removing default field values.
what if I want a conditional rule for "at least one selection"?