[InfoPath] limiting a repeating field and setting Maximum Occurrence
Problem:
Sometimes in InfoPath 2007 you need a way to limit a repeating field and putting for it Max limit…
This is a usual scenario, for example you are designing a form that will allow the user to add family members,,,
Now there is nothing limiting the user from keeping adding members!!
So how can we do it?
(Optional Concepts) Before we start:
I want to make sure before we start, that the reader understand what is a repeating field…
When you insert a filed in your schema in InfoPath, you can double click on the field and choose properties…
Here go and make sure that the repeating checkbox is selected,, what does this mean?
It means that this field is repeatable inside the schema, and if you actually know about writing XML schemas which are called XSD files, you will find something like this:
<xsd:element ref="my:FamilyMember" minOccurs="0" maxOccurs="unbound"/>
This is an element with two attributes that specify how many time should this element appear in the list,
How can you limit maximum number of a repeating section?
This is actually very easy what you need to do is:
After building the form, save the template,,
Rename and open the template as a cab file.. (for more information on this read this article: https://blogs.msdn.com/wael/archive/2007/04/29/infopath-how-to-modify-the-xsn-file-and-the-inside-xml.aspx)
Now, go to the a file called myschema.xsd and edit it in notepad…
You will find something similar to this:
<xsd:element ref="my:RepeatingFieldName" minOccurs="0" maxOccurs="unbound"/>
Change the value of maxOccurs to any number you want in which you want to limit the user to for example here I want the user not to add more that 3 family members
After changing your xml should be something like this:
<xsd:element ref="my:RepeatingFieldName" minOccurs="0" maxOccurs="3"/>
Save your XSD file and close it,,,
Re-package your XSN,,,,
Go and double click on your XSN file,,,
Test it and try to add more that 3 family members, you will get something like this:
Note: if you don't know how to package and repackage you XSN you need to follow the link to get the complete understanding of the process: https://blogs.msdn.com/wael/archive/2007/04/29/infopath-how-to-modify-the-xsn-file-and-the-inside-xml.aspx
Conclusion:
By this you know now how to set and limit the user to fill a repeating field with a limited number of repetitions,,,
Comments
Anonymous
February 29, 2008
Great post, thanks for this, came in handy limiting some repeating fields as per guidelines. http://www.wiinjamod.comAnonymous
August 12, 2008
The comment has been removedAnonymous
November 06, 2008
Nice tip, but I'm with Craig..in order for this to be usable, one would need to do a custom alert when the max was reached. The archaic error message isn't a great user experience.Anonymous
November 09, 2008
The comment has been removedAnonymous
November 30, 2009
The comment has been removedAnonymous
January 18, 2011
The comment has been removed