Compartir a través de


[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:

  1. After building the form, save the template,,

  2. 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)

  3. Now, go to the a file called myschema.xsd and edit it in notepad…

  4. You will find something similar to this:

    <xsd:element ref="my:RepeatingFieldName" minOccurs="0" maxOccurs="unbound"/>

  5. 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

  6. After changing your xml should be something like this:

    <xsd:element ref="my:RepeatingFieldName" minOccurs="0" maxOccurs="3"/>

  7. Save your XSD file and close it,,,

  8. Re-package your XSN,,,,

  9. Go and double click on your XSN file,,,

  10. 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,,,