https://github.com/ryanb/nested_form/
You can either just use it or you can use it for inspiration on your own code.
Best,
Rob
On Jun 28, 2012, at 10:23 PM, Graeme Worthy wrote:
> Here's how i'd start doing it.
>
> function NestedFields(form){
> this.form = form;
> this.field_sets = []
>
> }
>
> NestedCounter.prototype = {
> add_field_set: function(field_set) {
> this.field_sets.push(field_set);
> },
>
> count: function(){
> return this.field_sets.length()
> },
>
> }
>
> when you initialize the page, pass the dom element of the form to the
> constructor.
>
> var some_form = document.getElementById('form_id');
> var nest_o_tron = new NestedFields(some_form);
>
> then you don't rely on your dom to hold the state, you have a js object that
> does this.
> call nest_o_tron.add_field_set(your html) from whatever's doing the building;
> and nest_o_tron.count() gives you the current count;
>
>
>
>
>
> On Thursday, June 28, 2012 at 4:39 PM, Chris McCann wrote:
>
>> SD Ruby,
>>
>> I'm struggling with a Javascript issue that I'm hoping one of you gurus can
>> help with.
>>
>> One of my forms has a JS link that adds additional fields to the form for a
>> nested form attribute. There's also a hidden field that should have an
>> incrementing number in it that will increment for each additional set of
>> nested fields that's added.
>>
>> I can't sort out how to keep a JS var to hold the "next" increment number
>> and to set the hidden field value to that value when the new nested fields
>> are added.
>>
>> Any suggestions?
>>
>> Thanks,
>>
>> Chris
>>
>> --
>> SD Ruby mailing list
>> [email protected]
>> http://groups.google.com/group/sdruby
>
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby