Limit Repeating Rows

R

Rick Morgan

Hi All,
I can't be the only one to have this problem, but I'm a newbie and don't
know what else to try. I need to limit the number of rows allowed in a
repeating table. I've searched the dicussion boards, Google, Yahoo, you name
it. All I can find is that it will take some sort of script, but no further
details than that. Can someone point me in the right direction?

Thank you in advanced.
 
J

JR

Hi Rick,

I had the exact same problem and the only way I found was to use code. We created a repeating table with only one row and disabled the user's ability to add/remove rows. Then, in the form's OnLoad event, we simply cloned the one row and appended it the required number of times.

In our case, we had to accomplish this through unmanaged code (jscript) instead of managed code (c#), so I can provide you a jscript example if you'd like.
 
R

Rick Morgan

I would greatly appreciate any code you'd be willing to post. Thank you for
the help!
 
J

JR

Our code has a number of additional complexities, but this should do the trick..

=======================
var parent = XDocument.DOM.selectSingleNode("//my:Fields/my:parentContainer"); // parent container
var children = XDocument.DOM.selectNodes("//my:Fields/my:parentContainer/my:repeatingRow"); // repeating rows

var clone = children.nextNode().cloneNode(true); // clone the first repeating row

for (i = 0; i < number_of_rows_to_add; i++)
{
parent.appendChild(clone);
}
=======================
 
R

Rick Morgan

Hi JR,
Please forgive my ignorance, but as I said, I'm a newbie. I went to the
Tools => Programming => On Load Event... This brought up the code editor and
I pasted your code into the "// Write your code here" area (I removed the
original comment). From the looks of things, I'm supposed to replace
"parentContainer" (both places), "repeatingRow", and "number_of_rows_to_add"
with my own values. "numer_of_rows..." was pretty self explainatory.
However, I'm having trouble finding the values for the other two
replacements. Could you possibly point me in the right direction?

If it would be easier to walk my though a new form (so I have all default
values) that would be fine. Once I have a general idea of where to look I'm
hoping I can figure it out from there.

Thank you for your patience and help.
 
J

JR

Sorry Rick,

I've been out of the office for a couple days..

repeatingRow = the name you gave to your repeating rows
parentContainer = name of the immediate parent folder containing the repeatingRow
number_of_rows_to_add = number of rows you'd like to add.. :)

The part that is: //my:Fields/my:parentContainer should be replaced with the name
each folder in the structure down to the parentContainer.

For example:
look at your Data Source view, if your folder structure looks like this:

SomeForm
Folder_A
SubFolder_1
parentContainer
repeatingRow
SubFolder_2
Folder_B
Folder_C
...

then replace these two lines:
XDocument.DOM.selectSingleNode("//my:Fields/my:parentContainer");
XDocument.DOM.selectNodes("//my:Fields/my:parentContainer/my:repeatingRow");

with these two:

XDocument.DOM.selectSingleNode("//my:SomeForm/my:Folder_A/my:SubFolder_1/my:parentContainer");
XDocument.DOM.selectNodes("//my:SomeForm/my:Folder_A/my:SubFolder_1/my:repeatingRow");

Hope that's what you're looking for..
 
R

Rick Morgan

Hi JR,
We got it to work with a slight teak or two. Here is the final code that
did the trick. Thanks again for your help:
==========================
var parent =
XDocument.DOM.selectSingleNode("//my:Fields/my:parentContainer"); // parent
container
var children =
XDocument.DOM.selectNodes("//my:Fields/my:parentContainer/my:repeatingRow");
// repeating rows

var clone = children.nextNode().cloneNode(true); // clone the first
repeating row

for (i = 0; i < number_rows_to_add; i++)
{
parent.appendChild(clone);
clone = clone.cloneNode(true);
}
 

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