I observed the same behavior for SQLFORM.factory generated read-only forms.
I ran into this when I had a table with lots of fields for which I wanted
to create forms that displayed/edited only a selection of the
fields. SQLFORM.factory is the way to go.
Having the readonly form ignore the prepopulated form.vars looks like a bug
to me.
On Friday, November 4, 2011 5:21:50 PM UTC+1, pepper_bg wrote:
>
> This got solved by using the fact that Field.default could be
> manipulated *after* the Field has been created (following the above
> line of examples):
>
> def build_form(readonly=False):
> #create fields or get from
> db
> field1=Field('test')
> field2=db.my_table.best
> #set
> defaults
> field1.default='abc'
> field2.default='123'
> #give it to the
> form
> form = SQLFORM.factory( *[field1, field2], readonly=readonly )
>
> def frm():
> form = build_form( readonly=True )
> return dict(form=form)
>
> So readonly=True and no need of form.accepts. The lesson (if I am
> still not missing something) - if you want to reuse a SQLFORM.factory
> form and make it readonly set the defaults using Field.default and not
> Form.vars. Verrrrry particular...
>
--
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/groups/opt_out.