I would not use an additional table unless you plan to ever search by phone 
numbers. I would do:

db.define_table ('institutions',
    Field('name'),
    Field('numbers','list:string'))

In controler:
form=SQLFORM(db.institution <http://db.institution.name/>)

In view:
{{=form}}

You can also do what you ask but you nee more logic:

db.define_table ('institutions',
    Field('name'))

db.define_table ('phone',
    Field('number'),
    Field('institution', 'reference institutions'))

In controller:

form=SQLFORM.factory(
    db.institution.name,
    Field('numbers','list:string')).process()
if form.accepted:
    i = db.insitution.insert(form.vars.name)
    for n in form.vars.numbers: db.phone.insert(institution=i, number=n)

In view:
{{=form}}

On Sunday, 11 January 2015 03:19:53 UTC-6, Przemysław wrote:
>
> Hi!
> I need to add extra fields to my custom form generated from some fields of 
> different tables. These extra fields are are additional phone numbers for 
> the institution.
> The code looks like this (here simplified for better readability): 
>
> In model:
> db.define_table ('institutions',
>     Field('name'))
>
> db.define_table ('phone',
>     Field('number'),
>     Field('institution', 'reference institutions'))
>
> In controler:
> form=SQLFORM.factory(
>     db.institution.name,
>     db.phone.number,
>     (.... many additional fields are here))
>
> In view:
> {{=form}}
>    
> The question is how to add another phone.number inputs on a user request. 
> I've successfully created ajax connection which adds an extra inputs on 
> button click but I really need to place this extra inputs for phone number 
> just below the default phone.number input. I have no concept how to insert 
> a placeholder for new inputs in a form created by SQLFORM. In fact I need 
> to create extra rows in existing table. Do you have any advise for my?
> Przemek      
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to