How to Limit number of repeating section - InfoPath Dev
in

InfoPath Dev

How to Limit number of repeating section

Last post 11-30-2009 05:37 PM by Patrick Halstead. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-05-2009 03:45 PM

    How to Limit number of repeating section

    Hi,

     I need to restrict user to insert max of 3 repeating section in the infopath form.

    User should not be able to add more than 3 repeating section.

    Can I do this through rule?

    - Thilakraj

     

  • 02-05-2009 04:12 PM In reply to

    Re: How to Limit number of repeating section

    I know of no way to accomplish this in the InfoPath designer, but for a fixed number (in your case 3) this is probably the easiest way to accomplish that:

    1. Save the template as its source files (from the File menu in the InfoPath designer)
    2. Open the schema (XSD) file in a text editor
    3. Find the line that refers to your repeating field and change the maxOccurs value from "unbounded" to the number you want
    4. Save the schema
    5. Right-click manifest.xsf and select Design
    6. Re-save the template
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-05-2009 04:31 PM In reply to

    Re: How to Limit number of repeating section

    Jimmy Rishe,

     Thanks for the quick reply.. I tried your suggestion but when the user try to add the 4 th section, infopath is not showing user friendly error message.. it shows "Infopath cannot insert the section or row because of an error". Is there anyway to customise this error message and show user friendly message to the user?

    Thanks,

    Thilakraj

  • 02-05-2009 06:58 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: How to Limit number of repeating section

    Hello,

    You have to add on before change event for that field then you have to check the number of nodes available in that list. If the count is exceeds your requirement then you to give one alert message and eventObj.ReturnStatus = false;

    Depends on your requirement you have to write the code and here is the sample,

    function msoxd_my_field2::OnBeforeChange(eventObj)

    {

    var repeatingNodes = XDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2");

    if(repeatingNodes.length > 3)

    {

    XDocument.UI.Alert("Exceed the nodes");

    eventObj.ReturnStatus = false;

    }

    }

    Note: If you want to set the message 'eventObj.ReturnMessage = "your message".

  • 02-06-2009 10:43 AM In reply to

    Re: How to Limit number of repeating section

     Hello, I'm using browser enabled form, so I believe I can’t use the above script. Is there any other way to limit the repeating section in browser enabled forms?

    Thanks,

    Thilakraj

     

  • 11-30-2009 01:19 PM In reply to

    Re: How to Limit number of repeating section

    It doesn't look like you can alter the error message that InfoPath displays when using Browser enabled forms, well without using code. What I have done in the past is to display an expression box with the error message desired and set conditional formating to display only when the number of occurences of the reapeating section is equal to the maximum. You still get an error message if you add another section, but better than what InfoPath provides out of the box. I tried adding a conditional format on the section to not allow adding once the number of ocurrences was at the maximum but that didn't work because it stops the user from removing sections as well.

  • 11-30-2009 02:41 PM In reply to

    Re: How to Limit number of repeating section

    Hello @all,

    I don´t know if I misunderstood the above mentioned problem but why can´t you just use an expression like

    Expression:     count(my:field1) >= "3"
    Condition:      Don´t allow users to insert or delete this control ==> Activate

    In my opinion that´s the easiest way to limit the number of sections that can be inserted.

    Regards,

    Karsten
  • 11-30-2009 05:20 PM In reply to

    Re: How to Limit number of repeating section

    Yeah I tried that as well, but found that when you hit the limit the user cannot delete any sections.  It would be good in sone cases but I needed to stop users from adding new items.  Its a pity the condition is both insert and delete and not seperated.

    In actual fact if you limit your forms to Browser based forms only, Form Services does display a nice error message when the XSD Schema has an upper bounds so you don't need to do anything other than that, its when you want a form to be edited in InfoPath when it displays the user unfriendly message.

     

  • 11-30-2009 05:37 PM In reply to

    Re: How to Limit number of repeating section

    Modify the schema to add maxOccurs attribute to the node. You'll have to save as source files. Open up the XSD. Find the node and insert maxOccurs on it. Then save and right click manifest.xsf to get back into Design mode so you can publish with the manually tweaked schema.

    Ain't InfoPath wonderful! :)

    Funny! That's the same thing Jimmy recommended. :)

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.