Thanks. That helped me too! But i have no idea how it did it. Need to read
up on widgets.
All i wanted to do was add the "readonly" attribute to a form field. I
thought the following would have worked (from the book). Is it intended to
add attributes?
If you need to add custom attributes to fields, you can simply do this:
db.table.field.extra = {}
On Friday, 9 August 2013 06:04:18 UTC+10, Anthony wrote:
>
> Nice. I think we should add an argument to Field() that takes a dictionary
> of args to pass to the field's widget (or maybe just add **kwargs to
> Field() and pass kwargs to the widget). For now, though, if that's all you
> want to do, you can do something like this:
>
> def widget(**kwargs):
> return lambda field, value, kwargs=kwargs: SQLFORM.widgets[field.type
> ].widget(field, value, **kwargs)
>
> db.define_table('mytable',
> Field('myfield', widget=widget(_placeholder='my placeholder',
> _readonly=True)))
>
> That should work for most fields -- would need some additional logic to
> accommodate fields that involve special widgets (e.g., fields with an
> IS_IN_DB validator that automatically get an options widget).
>
> Anthony
>
>
>
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/48a54766-00c2-4887-9613-46cf22a1021a%40googlegroups.com.