Using validation rules in InfoPath 2010 we can easily make certain fields become required based on a condition we set within the rule.
The example below requires the 'Employment end date' field only to become required if the user selects 'Fixed term' in the 'Employment type' field.
Basic form with some fields added
As we want to make the 'Employment end date' conditionally required, we need to select that field and click on the 'Manage Rules' icon in the Home ribbon.
Now that the 'Rules' menu is open, click new and select a 'Validation' rule.
Give the rule a name and then click on 'None' under the Condition heading.
In this example our condition is 'If Employment type is equal to Fixed term' then we want the field to be required.
Type 'Required' into the ScreenTip box and this is what will appear as a tip on the form when the field becomes required.
If you published the form and then opened a new item you would find that the field is now conditionally required. However you will not be able to submit using this rule as it is! see below.
'Employment end date' is not required on load.
With 'Employment type' changed to 'Fixed term' the field is now marked as required.
But if you try adding data to the newly required field, you will get a red dashed line and then a validation error should you try to submit the form. The error will be along the lines of "InfoPath cannot submit the form because it contains errors. Errors are marked with either a red asterisk (required fields) or a red, dashed border (invalid values).
There is an easy fix for this, by tweaking our validation rule condition we can avoid this validation error.
Go back to our field validation rule and modify the condition.
We need to tweak our condition to only make the field required if it is also blank.
Publish your form and you will have conditionally required fields with no validation errors!
Matt you helped me a lot! Thank you for this blog, I don't understand why I must complete the "is blank" rule but I'll just follow the instructions. :)
ReplyDeleteGlad it helped!
ReplyDeleteHi Matt. I need to make a Person /Group and Choice (Multi-Select) field required based on the value of another field. Your example above looks PERFECT, but Validation is grayed out for the Person / Group field and the Choice (Multi-Select). Any ideas how to apply Validation to those types of fields?
ReplyDeleteLooks like you need the "is blank" extension because Infopath doesn't work right. I mean, c'mon, I have the rule set the field to required, enter some data and THEN Infopath tells me the field can't be blank?
ReplyDeleteJust another bug ...
Incredible....you have no idea how long I have tried to figure out how to avoid the date error. Many thanks for this.
ReplyDeleteUnfortunately validation rules are only available to use on some of the field types, and the person and group picker field is not one of them.
ReplyDeleteThere are workarounds (not perfect), one being to put the person field inside a section and hiding it until it becomes required.
Take a look at this link
http://sharepoint.stackexchange.com/questions/44345/sharepoint-2010-people-picker-limitations-issue
Thank you so much! I never knew about the "is blank" requirement to remove the validation errors. Easy peasy
ReplyDeleteWow, many many thanks! I've been battling this error all morning, would have never though of adding that condition. Makes no sense but it does work :)
ReplyDeleteThank you Matt for this posting. I was at my wits trying to figure this out. Even thought I don't understand the need for the 2nd conditional check ("is blank") but it does fix the problem. Leave it to Microsoft to code something like this.
ReplyDeleteThank you very much, Matt! You've saved my life!!
ReplyDeleteNever mind, i just made the last comment about not being able to get this to work, and USER ERROR! It worked!!
ReplyDeleteThank you for your clear instructions! Very helpful!
ReplyDeleteThanks mate. That was super cool and helpful... Cheers
ReplyDeleteMatt-Matt... thanks so much. No really, THANKS! Hope you have a great day... mine just got better! (BA)
ReplyDeleteGreat help Matt! Thank you for sharing!
ReplyDeleteThanks for this helpful information I agree with all points you have given to us. I will follow all of them.
ReplyDeleteSharePoint 2013 Online Training
Matt - thanks for sharing! It worked perfectly and actually does make sense once you stop and think about it. I spent hours trying to get it to work and reading through other posts before finding your blog.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis was very helpful. Thank you!
ReplyDeleteThanks for sharing Matt! Like many other posters, I was scratching my head as to why the conditional requirement behaved like it did. Found your post, added the second condition, and it fixed it.
ReplyDeleteSaved me hours of research and experimentation!!!
ReplyDeleteThanks Matt! You're a life saver! Been scratching my head over this for days.
ReplyDelete