Method 1 can be easily generalized in a function that set the placeholder
for all sqlform fields and strip away all labels and comments:
def autoset_form_placeholders(form, form_labels=False, form_comments=False):
for f in form.fields:
if f == 'id':
pass
else:
form.custom.widget[f].update(_placeholder=f)
if not form_labels:
form.elements('.w2p_fl', replace=None)
if not form_comments:
form.elements('.w2p_fc', replace=None)
On Thursday, June 23, 2011 6:04:55 PM UTC+2, Anthony wrote:
>
> A couple other methods:
>
> 1. In the controller or view:
>
> form.custom.widget.first_name.update(_placeholder="first name")
>
> or
>
> 2. Customize the db.yourtable.first_name widget:
>
> db.define_table('yourtable', Field('first_name',
> widget=lambda field,value: SQLFORM.widgets.string.widget(field, value,
> _placeholder='first name')),
> [rest of table definition])
>
> or specify it after table definition via
> db.yourtable.first_name.widget=lambda...
>
> Method #2 will apply the change to all forms that include that field.
>
> There should probably be an easier/more straightforward way to do this,
> though. All the widgets take keyword arguments, but it doesn't look like
> there's an easy way to pass them in when the widgets are associated with db
> table fields.
>
> Anthony
>
>
> On Thursday, June 23, 2011 10:55:19 AM UTC-4, Massimo Di Pierro wrote:
>
>> form.element(_id='...')['_placeholder']='...'
>>
>> On Jun 23, 9:24 am, Carl <[email protected]> wrote:
>> > I'm using custom forms in my views using this format:
>> > {{=form.custom.widget.first_name}}
>> >
>> > I'd like to use HTML's placeholder attribute to input tags: e.g.,
>> > <input type="text" placeholder="first name" />
>> >
>> > Today: what are the ways to enable this? Obviously happy to drop the
>> > {{=form.custom.widget.first_name}} format and use something else.
>> >
>> > Tomorrow: might it be a good idea to add placeholder attribute to
>> > db.Field() in a similar fashion to how 'label' has already been added?
>
>
--
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/d/optout.