Repeating sections

A

Andrew

Is there a way to do this either through code or some how setting the minimum
occurrences to 1 instead of 0

Thanks,
Andrew
 
B

Bojana Marjanovic [MSFT]

Two ways I can think of to accomplish this:

1. When working on your form template, you can save it as Source Files (from
the File menu). You can then open the myschema.xsd file and adjust the min
occurs value for your particular element. This will be respected in InfoPath
and an error will appear if a user tries to delete the last item.
Unfortunately, this method does come with a somewhat unattractive error
message.

2. Use the onBeforeChange/Changing event to check if this is the last
instance of that particular section. If it is, you can programmatically
prevent the change and display a dialog with an error message.
Here's an example:
public void repeatingTable_OnBeforeChange(DataDOMEvent e)

{

//check for a delete operation

if (e.Operation == "Delete")

{ IXMLDOMNode table = e.Site;

//check to see if this is the last row

if (table.firstChild.nextSibling == null ||
table.firstChild.nextSibling.nodeName == "#text")

{ e.ReturnMessage = "You must include at least one row in this
table.";

e.ReturnStatus = false;

}

}

}


Let me know if this helps,
Bojana
 
A

Andrew

Since I have c# code behind the form I went ahead and used a variation of
your second suggestion.

IXMLDOMNodeList NodeLst = e.Source.selectNodes("/my:myFields/my:LI_PO");

if ( NodeLst.length == 0)
{
e.ReturnMessage = "You must include at least one Line Item.";
e.ReturnStatus = false;
}

Thanks,

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top