I've made something like this work. Perhaps something like this is
what you're looking for?
*UNTESTED CODE* but same exact concept as what I got to work for me
when making a list of forms.
tags = db(db.tags).select()
# For readability or if you need to do calculations or append more to
your
# SQLFORM
taglist = []
for tag in tags:
taglist.append( SQLFORM(db.tags, record=tag.id, deletable = True,
showid=False, fields=['tag'], labels = {'tag':''}, submit_button =
'update',
delete_label = 'delete ', record_id = None, formstyle = 'table2cols',
separator = '', _name=tag.tag )
# List comprehension is faster than above code though
taglist = [ SQLFORM(db.tags, record=tag.id, deletable = True,
showid=False, fields=['tag'], labels = {'tag':''}, submit_button =
'update',
delete_label = 'delete ', record_id = None, formstyle = 'table2cols',
separator = '', _name=tag.tag) for tag in tags ]
# Ater building your list of forms you need to iterate through it
# and give them an .accepts(...):
for form in taglist:
if form.accepts(request.vars, formname=tag.tag):
response.flash = 'updated'
else:
response.flash = 'form has errors'
Be sure to include taglist=taglist or something to that effect in your
return dict.
I hope this can prove useful to you.
David
On Oct 8, 7:40 pm, monotasker <[email protected]> wrote:
> I need to present a list of edit forms, one for each tag in db.tags. I've
> written the controller below, but it doesn't work because (I think) the
> variable "thisform" is identical for each form. I think the problem is that
> I need to assign a unique variable name to each form (i.e., each time
> through the "for" loop). But since you can't use operators in a variable
> name, I'm not sure if this is possible. Is there a simple solution?
>
> tags = db(db.tags).select()
> taglist = []
> for tag in tags:
> thisform = SQLFORM(db.tags, record=tag.id, deletable = True,
> showid=False, fields=['tag'], labels = {'tag':''}, submit_button = 'update',
> delete_label = 'delete ', record_id = None, formstyle = 'table2cols',
> separator = '', _name=tag.tag)
> if thisform.accepts(request.vars, formname=tag.tag):
> response.flash = 'updated'
> else:
> response.flash = 'form has errors'
> taglist.extend(thisform)