SQLFORM.factory adding dynamic form

115 views
Skip to first unread message

Ramkrishan Bhatt

unread,
Mar 4, 2015, 3:52:46 PM3/4/15
to web...@googlegroups.com
Hi Everyone,
SQLFORM.factory can we create dynamic form for one to many relation. Like person can have multiple address. So how can we achieve with composit form with SQLFORM.factory with multiple tables.
Please send me example too.
Like I can add many address form than bulk record insertion.

黄祥

unread,
Mar 5, 2015, 12:19:34 AM3/5/15
to web...@googlegroups.com
perhaps you can create an address table and use list:reference in sqlform.factory
e.g. (not tested)
db.define_table('address', Field('address') )

def form_from_factory():
    form = SQLFORM.factory(
        Field('address', 'list:reference', requires = IS_IN_DB(db, db.address.id,  '%(address)s') ) )
    if form.process().accepted:
        response.flash = 'form accepted'
        session.address = form.vars.address
    elif form.errors:
        response.flash = 'form has errors'
    return dict(form = form)

best regards,
stifan

Ramkrishan Bhatt

unread,
Mar 5, 2015, 10:58:14 AM3/5/15
to web...@googlegroups.com

<type 'exceptions.SyntaxError'> table already defined: address



Anyway i guess you are not understanding requirement :-
SQLFORM.factory(table1,table2,table3)
if form.process().accepted:
      do something.

Now we want like we can add extra add table2 form in dynamically.
like in view

composit form of 
table1
table2 (option for add more form from table2)
table3 (option for add more form from table3)
submit for bulk insert # That i know using dict{}
but how to generate dynamic form from our table. 

Ramkrishan Bhatt

unread,
Mar 6, 2015, 4:24:42 PM3/6/15
to web...@googlegroups.com
No Solution for one to many composite form ?

Val K

unread,
Mar 23, 2015, 10:53:04 PM3/23/15
to web...@googlegroups.com
I think, there is no problem, but I am not sure that I understand what you want:
- do you want to edit/insert multiple records of/to the same table (person-address-relation for example) at once, per single form's accept? 
- do you want to edit/insert single records of/to few tables at once?
 or do you want it  all?

If you want to have dynamic form without submitting it or extra requests  (like list-widget)- you have to use JS.
Notice, that from redefined per controller call, you can add a button   'add address'  (for example) to your form and 
redefine form (i.e. add field) per button click  
Please, be more concrete 

Ramkrishan Bhatt

unread,
Mar 24, 2015, 9:17:45 PM3/24/15
to web...@googlegroups.com
I am looking from templating genrated form through SQLFORM.factory is possible that we can clone of address table Multiple time like one person can have multiple address using add address button. Than submit all together with bulk insert.

Paolo Valleri

unread,
Mar 25, 2015, 9:44:12 AM3/25/15
to web...@googlegroups.com
To fix the exception 'table already defined' use define_table() with redefine=True

Paolo
Reply all
Reply to author
Forward
0 new messages