Web2py's built in ajax offers an even simpler way.
The manual recommends you use components, though.
On Tuesday, March 19, 2013 1:03:21 PM UTC-4, Derek wrote:
>
> I would suggest having the 'register' page take only one address, and
> after creating, it redirects you to the 'view' of the client, which has a
> link to a page where it shows all addresses and allows you to ADD an
> address. You could also implement this in AJAX, which is what I would
> recommend.
>
> Here's an example from one of my sites. I use it to save software to a
> server.
>
> $.post("scripts/newSoftware", // name of function to call
> {
> py_server: $("#serverid").val(),
> py_guid: $("#guid").val(),
> py_version: $("#version").val(),
> py_who: $("#who").val(),
> py_jobs: $("#jobs").val(),
> py_comments: $("#comments").val()
> }
> ,function(data) { $('#softwarelisting').load('onlysoftware?ID='+ data);}
> );
>
> On Monday, March 18, 2013 5:33:41 PM UTC-7, Alex Glaros wrote:
>>
>> Does anyone know how to create a loop allowing variable number of child
>> records to be added to a parent?
>>
>> Here’s a sample where only one child is created. The “client” is the
>> parent record and “address” is the child record.
>> http://web2py.com/books/default/chapter/29/07
>>
>> Can anyone please type the code to show how to allow user to add variable
>> number of child records?
>>
>> If it’s easier to do not using factory, that’s fine.
>>
>> Thanks,
>>
>> Alex Glaros
>>
>>
>> One form for multiple tables
>>
>> model:
>>
>> db.define_table('client',
>>
>> Field('name'))
>>
>> db.define_table('address',
>>
>> Field('client','reference client',
>>
>> writable=False,readable=False),
>>
>> Field('street'),Field('city'))
>>
>> controller:
>>
>> def register():
>>
>> form=SQLFORM.factory(db.client,db.address)
>>
>> if form.process().accepted:
>>
>> id = db.client.insert(**db.client._filter_fields(form.vars))
>>
>> form.vars.client=id
>>
>> id = db.address.insert(**db.address._filter_fields(form.vars))
>>
>> response.flash='Thanks for filling the form'
>>
>> return dict(form=form)
>>
>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.