Limit Repeating Sections

F

Franck Dauché

Hi,

You can do it using code in the OnBeforeChange Event where you can count the
number of childNodes and you can cancel the Event if the Max was reached.

Franck Dauché
 
N

NikV

Franck;
I'm pretty new at this so please go into further detail. This is what I am
trying to accomplish:

I have template that will take data entry in from the user. The template is
designed to gather accomplishments for a department for the month. I have
several departments and each department has different set of categories that
have to be accomplished each month. I am catching these entries in by having
the user type text in textboxes. By using text boxes embedded in repeating
tables; is this the best way to go since I have to save all the inputted data
into MS SQL Database? Do you other recommendations on doing this?

Also can you go into detail steps on how to use the OnBeforeChange Event you
describe below. Thanks!
 
F

Franck Dauché

Hi,

Here is an example:

create new IP project (with C#)
In the data source under myFields, Add 1 group called Test
Under Test add 1 repeating group: Test2
Under Test2, add 1 Text field test3

Now, drop Test on your form as a section
drop Test2 in that section as a repeating Table

Now, in your data source, select Test2, right-click and go to the
"Validation and Event Handlers" Tab.
select "OnBeforeChange" from the drop-down.
Click "Edit"

then insert that code the OnBeforeChange Event:

[InfoPathEventHandler(MatchPath="/my:myFields/my:Test/my:Test2",
EventType=InfoPathEventType.OnBeforeChange)]
public void Test2_OnBeforeChange(DataDOMEvent e)
{
IXMLDOMNode oNode = thisXDocument.DOM.selectSingleNode("//my:Test");
if (oNode != null)
{
if (oNode.childNodes.length > 5)
{
e.ReturnMessage = "Sorry can't have more than 3 entries!";
e.ReturnStatus = false;
}
}
}

It limits the number of textboxes to 3. You can start from there...

Hope that it helps.

Franck Dauché
 
N

NikV

Franck;
The first line in your response was to create a IP project "using C#". I've
never used C# before, I just start my projects in InfoPath. Does that make
sense?

Franck Dauché said:
Hi,

Here is an example:

create new IP project (with C#)
In the data source under myFields, Add 1 group called Test
Under Test add 1 repeating group: Test2
Under Test2, add 1 Text field test3

Now, drop Test on your form as a section
drop Test2 in that section as a repeating Table

Now, in your data source, select Test2, right-click and go to the
"Validation and Event Handlers" Tab.
select "OnBeforeChange" from the drop-down.
Click "Edit"

then insert that code the OnBeforeChange Event:

[InfoPathEventHandler(MatchPath="/my:myFields/my:Test/my:Test2",
EventType=InfoPathEventType.OnBeforeChange)]
public void Test2_OnBeforeChange(DataDOMEvent e)
{
IXMLDOMNode oNode = thisXDocument.DOM.selectSingleNode("//my:Test");
if (oNode != null)
{
if (oNode.childNodes.length > 5)
{
e.ReturnMessage = "Sorry can't have more than 3 entries!";
e.ReturnStatus = false;
}
}
}

It limits the number of textboxes to 3. You can start from there...

Hope that it helps.

Franck Dauché


NikV said:
Franck;
I'm pretty new at this so please go into further detail. This is what I am
trying to accomplish:

I have template that will take data entry in from the user. The template is
designed to gather accomplishments for a department for the month. I have
several departments and each department has different set of categories that
have to be accomplished each month. I am catching these entries in by having
the user type text in textboxes. By using text boxes embedded in repeating
tables; is this the best way to go since I have to save all the inputted data
into MS SQL Database? Do you other recommendations on doing this?

Also can you go into detail steps on how to use the OnBeforeChange Event you
describe below. Thanks!
 
F

Franck Dauché

You are using Scripting instead of Managed code.
Do exectly the step as I explained in my last email, the code to be inserted
in the OnBeforeChange is now:

function msoxd_my_Test2::OnBeforeChange(eventObj)
{
var oNode = XDocument.DOM.selectSingleNode("//my:Test");
if (oNode != null)
{
if (oNode.childNodes.length > 5)
{
eventObj.ReturnMessage = "Sorry can't have more than 3 entries!";
eventObj.ReturnStatus = false;
}
}

}

Franck Dauché


NikV said:
Franck;
The first line in your response was to create a IP project "using C#". I've
never used C# before, I just start my projects in InfoPath. Does that make
sense?

Franck Dauché said:
Hi,

Here is an example:

create new IP project (with C#)
In the data source under myFields, Add 1 group called Test
Under Test add 1 repeating group: Test2
Under Test2, add 1 Text field test3

Now, drop Test on your form as a section
drop Test2 in that section as a repeating Table

Now, in your data source, select Test2, right-click and go to the
"Validation and Event Handlers" Tab.
select "OnBeforeChange" from the drop-down.
Click "Edit"

then insert that code the OnBeforeChange Event:

[InfoPathEventHandler(MatchPath="/my:myFields/my:Test/my:Test2",
EventType=InfoPathEventType.OnBeforeChange)]
public void Test2_OnBeforeChange(DataDOMEvent e)
{
IXMLDOMNode oNode = thisXDocument.DOM.selectSingleNode("//my:Test");
if (oNode != null)
{
if (oNode.childNodes.length > 5)
{
e.ReturnMessage = "Sorry can't have more than 3 entries!";
e.ReturnStatus = false;
}
}
}

It limits the number of textboxes to 3. You can start from there...

Hope that it helps.

Franck Dauché


NikV said:
Franck;
I'm pretty new at this so please go into further detail. This is what I am
trying to accomplish:

I have template that will take data entry in from the user. The template is
designed to gather accomplishments for a department for the month. I have
several departments and each department has different set of categories that
have to be accomplished each month. I am catching these entries in by having
the user type text in textboxes. By using text boxes embedded in repeating
tables; is this the best way to go since I have to save all the inputted data
into MS SQL Database? Do you other recommendations on doing this?

Also can you go into detail steps on how to use the OnBeforeChange Event you
describe below. Thanks!

:

Hi,

You can do it using code in the OnBeforeChange Event where you can count the
number of childNodes and you can cancel the Event if the Max was reached.

Franck Dauché

:

Is there a way to limit how many repeating sections you can have?
 
N

NikV

Franck;
I am a beginner. In the first line you wrote create an IP Project from C#.
How do I do that?

Franck Dauché said:
Hi,

Here is an example:

create new IP project (with C#)
In the data source under myFields, Add 1 group called Test
Under Test add 1 repeating group: Test2
Under Test2, add 1 Text field test3

Now, drop Test on your form as a section
drop Test2 in that section as a repeating Table

Now, in your data source, select Test2, right-click and go to the
"Validation and Event Handlers" Tab.
select "OnBeforeChange" from the drop-down.
Click "Edit"

then insert that code the OnBeforeChange Event:

[InfoPathEventHandler(MatchPath="/my:myFields/my:Test/my:Test2",
EventType=InfoPathEventType.OnBeforeChange)]
public void Test2_OnBeforeChange(DataDOMEvent e)
{
IXMLDOMNode oNode = thisXDocument.DOM.selectSingleNode("//my:Test");
if (oNode != null)
{
if (oNode.childNodes.length > 5)
{
e.ReturnMessage = "Sorry can't have more than 3 entries!";
e.ReturnStatus = false;
}
}
}

It limits the number of textboxes to 3. You can start from there...

Hope that it helps.

Franck Dauché


NikV said:
Franck;
I'm pretty new at this so please go into further detail. This is what I am
trying to accomplish:

I have template that will take data entry in from the user. The template is
designed to gather accomplishments for a department for the month. I have
several departments and each department has different set of categories that
have to be accomplished each month. I am catching these entries in by having
the user type text in textboxes. By using text boxes embedded in repeating
tables; is this the best way to go since I have to save all the inputted data
into MS SQL Database? Do you other recommendations on doing this?

Also can you go into detail steps on how to use the OnBeforeChange Event you
describe below. Thanks!
 
F

Franck Dauché

Hi,

To do this you need to have Visual Studio .Net 2003 installed on your
machine as well as the Toolkit (bridge between VS.Net and InfoPath).

You can achieve the same result using Scripting. In that case, line 1
becomes: Start InfoPath and create a new Blank form.
Create Test1 (group), Test2 (repeating group), and test3 (string) as
described in my original email, and use code like this:

function msoxd_my_Test2::OnBeforeChange(eventObj)
{
var nodeList = XDocument.DOM.selectNodes("//my:Test1/my:Test2");
if (nodeList.length>3)
{
eventObj.ReturnMessage = "Sorry can't have more than 3 entries!";
eventObj.ReturnStatus = false;
}

}

This will limit entries to 3...

Franck


NikV said:
Franck;
I am a beginner. In the first line you wrote create an IP Project from C#.
How do I do that?

Franck Dauché said:
Hi,

Here is an example:

create new IP project (with C#)
In the data source under myFields, Add 1 group called Test
Under Test add 1 repeating group: Test2
Under Test2, add 1 Text field test3

Now, drop Test on your form as a section
drop Test2 in that section as a repeating Table

Now, in your data source, select Test2, right-click and go to the
"Validation and Event Handlers" Tab.
select "OnBeforeChange" from the drop-down.
Click "Edit"

then insert that code the OnBeforeChange Event:

[InfoPathEventHandler(MatchPath="/my:myFields/my:Test/my:Test2",
EventType=InfoPathEventType.OnBeforeChange)]
public void Test2_OnBeforeChange(DataDOMEvent e)
{
IXMLDOMNode oNode = thisXDocument.DOM.selectSingleNode("//my:Test");
if (oNode != null)
{
if (oNode.childNodes.length > 5)
{
e.ReturnMessage = "Sorry can't have more than 3 entries!";
e.ReturnStatus = false;
}
}
}

It limits the number of textboxes to 3. You can start from there...

Hope that it helps.

Franck Dauché


NikV said:
Franck;
I'm pretty new at this so please go into further detail. This is what I am
trying to accomplish:

I have template that will take data entry in from the user. The template is
designed to gather accomplishments for a department for the month. I have
several departments and each department has different set of categories that
have to be accomplished each month. I am catching these entries in by having
the user type text in textboxes. By using text boxes embedded in repeating
tables; is this the best way to go since I have to save all the inputted data
into MS SQL Database? Do you other recommendations on doing this?

Also can you go into detail steps on how to use the OnBeforeChange Event you
describe below. Thanks!

:

Hi,

You can do it using code in the OnBeforeChange Event where you can count the
number of childNodes and you can cancel the Event if the Max was reached.

Franck Dauché

:

Is there a way to limit how many repeating sections you can have?
 

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