inputs = []for i in range(0,10): inputs.append(db.table1.field1) inputs.append(db.table1.field2)
form = SQLFORM.factory(*inputs)inputs = []
for i in range(0,10): inputs.append(Field('field1', 'type...', ...)) inputs.append(Field('field2', 'type...', ...))
form = SQLFORM.factory(*inputs)Hello,I would like to build a bunch insert form and I wouldn't have to duplicate fields definition for SQLFORM.factory
I try naively
inputs = []for i in range(0,10):inputs.append(db.table1.field1)inputs.append(db.table1.field2)form = SQLFORM.factory(*inputs)
But even if I get 10 inputs of each in "inputs" they all refer to the same instance so when I render the form with SQLFORM.factory, I only get my 2 fields, but I would have 10 of each...Is there a way to avoid doing this :
inputs = []for i in range(0,10):inputs.append(Field('field1', 'type...', ...))inputs.append(Field('field2', 'type...', ...))form = SQLFORM.factory(*inputs)
Because doing the last example would make my code much more less DRY.
ThanksRichard
--
---
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
for i in range(0,10):
inputs.append(db.table1.field1.clone(name='%s_%s' % (db.table1.field1.name, i)))Since it is not documented yet could it be modified in a near future? I mean, if I start using it could I experiment bugs to trigger in my app in the future cause the syntax change or something like that?
db.company.insert(company=form.vars['company_%s' % i])--
--
Is that the entire view? You haven't included the form anywhere, so there are no company_0, company_1, etc. inputs.
@Steve it exactly what I have in mind, except in my case the form has to be generic for many differents tables, but if you only one table to bunch insert, that way it works fine...Notice, if you create more inputs then the number your users will need (not 3 records for instance) you get in trouble if you have not null requires or IS_IN_DB or other validators)... So I use an other form to catch the number of input the user is needing and I pass it buy the URL as a vars something like that :URL(c='controller', f='bunch_func', vars=dict(nb_inputs=3))Then I use it in range function :for i in range(0, int(request.vars.nb_inputs))
Notice, if you create more inputs then the number your users will need (not 3 records for instance) you get in trouble if you have not null requires or IS_IN_DB or other validators)... So I use an other form to catch the number of input the user is needing and I pass it buy the URL as a vars something like that :URL(c='controller', f='bunch_func', vars=dict(nb_inputs=3))Then I use it in range function :for i in range(0, int(request.vars.nb_inputs))
--
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)
For more options, visit https://groups.google.com/d/optout.
Thanks dude,Yoel2016-03-09 18:01 GMT-04:00 Richard Vézina <ml.richa...@gmail.com>:I think I had publish something in the past that address your requirement...search for inline form or something... I don't have time to search now...Can have a look tomorrow what can I share...
--Saludos,YB