Creating Repetition Rows Dynamically

5 views
Skip to first unread message

bobhaugen

unread,
Nov 19, 2007, 12:32:13 PM11/19/07
to Web Forms 2.0 Implementation
I want to add new repetition rows to a template from client-side
javascript.

I looked at Test Case 20: Creating Repetition Templates Dynamically
http://webforms2.googlecode.com/svn/trunk/testsuite/020.html

It does not seem to work, and a bunch of the source is commented
out.

I am not sure it is relevant to what I want to do anyway, but its
failure prompted this message.

I'm looking into addRepetitionBlock() and will do some experiments,
but some guidance and/or an example would be nice.

Will report back if I get something to work.

Cheers,
Bob

Weston Ruter

unread,
Nov 19, 2007, 1:23:42 PM11/19/07
to webf...@googlegroups.com
I haven't yet programmed the functionality to create repetition templates dynamically. I added that test case to demonstrate what cannot yet be done but what should be able to be done. Note that the test case fails with Opera's native implementation, so obviously, creating repetition templates is not well supported.

bobhaugen

unread,
Nov 19, 2007, 2:37:31 PM11/19/07
to Web Forms 2.0 Implementation
On Nov 19, 12:23 pm, "Weston Ruter" <westonru...@gmail.com> wrote:
> I haven't yet programmed the functionality to create repetition templates
> dynamically.

Any reason I cdn't call addRepetitionBlock() from my own code?

I mean, when you write that you "haven't yet programmed the
functionality to create repetition templates dynamically", do you mean
just creating templates, or also adding rows to existing templates?

In this situation, I am happy to create the template statically, I
just want to add rows dynamically based on a user selection of the
parent object for the child rows.

Or am I going up a blind alley and shd just roll my own entry tables
in this case?

bobhaugen

unread,
Nov 19, 2007, 2:58:15 PM11/19/07
to Web Forms 2.0 Implementation
On Nov 19, 1:37 pm, bobhaugen <bob.hau...@gmail.com> wrote:
> Any reason I cdn't call addRepetitionBlock() from my own code?

Looks like it works a charm. Maybe I'll run into some hidden rocks,
but so far so good.

Weston Ruter

unread,
Nov 19, 2007, 3:38:39 PM11/19/07
to webf...@googlegroups.com
Oh, right, I mean creating repetition templates dynamically, not creating blocks dynamically. To do the latter, simply call addRepetitionBlock as you mentioned. Thanks for pointing that out.

bobhaugen

unread,
Nov 19, 2007, 7:23:20 PM11/19/07
to Web Forms 2.0 Implementation
Here's my current test code, which appears to work. Any suggestions
for improvement? A better way to get all the blocks for removal?

function addRow()
{
var template=dojo.byId("order");
template.addRepetitionBlock();

}

function removeAllRows()
{
var orders=dojo.html.getElementsByClass("order");
for(var i=0;i<orders.length;i++)
{
var orderItem=orders[i];
if(orderItem.repetitionType==RepetitionElement.REPETITION_BLOCK)
{
orderItem.removeRepetitionBlock();
}
}
}

Weston Ruter

unread,
Nov 19, 2007, 7:28:56 PM11/19/07
to webf...@googlegroups.com
You can use the "repetitionBlocks" property on the repetition template element:

function removeAllRows(){
    var template=dojo.byId("order");
    while(template.repetitionBlocks.length){
        template.repetitionBlocks[0].removeRepetitionBlock();

bobhaugen

unread,
Nov 19, 2007, 8:10:14 PM11/19/07
to Web Forms 2.0 Implementation
On Nov 19, 6:28 pm, "Weston Ruter" <westonru...@gmail.com> wrote:
> You can use the "repetitionBlocks" property on the repetition template
> element:
>
> function removeAllRows(){
> var template=dojo.byId("order");
> while(template.repetitionBlocks.length){
> template.repetitionBlocks[0].removeRepetitionBlock();
> }
>
> }
>

Cool! Much cleaner.
Reply all
Reply to author
Forward
0 new messages