One option might be something like this:
for field in db.auth_user:
field.widget = lambda f, d, label=field.label: SQLFORM.widgets[f.type].
widget(f, d, _placeholder=label)
field.label = ''
That will set the placeholder for each field to the value of the label and
then set the label to an empty string so it won't display. Another option
is to use the formstyle argument to SQLFORM and write your own formstyle
function. It's not yet documented in the book, but formstyle can now be a
function that takes the form and a list of fields and returns the entire
form body (except the opening and closing form tags). For an example of
what the function should look like, see the one used for the "table3cols"
formstyle:
https://code.google.com/p/web2py/source/browse/gluon/sqlhtml.py#718.
Anthony
On Thursday, March 14, 2013 2:49:44 AM UTC-4, Alec Taylor wrote:
>
> How do I replace all forms to use the HTML5 `placeholder` rather than
> `label`?
>
> Here is how I currently do it:
>
> def signup_form_function():
> signup_form = SQLFORM(db.auth_user)
>
> for label in signup_form.elements('label'):
> label["_style"] = "display:none;"
>
> placeholders = {
> "email": "email address",
> "expertise": "expertise; press `+` to add more ->",
> }
> pwd = {
> "password": "password"
> }
> for input in signup_form.elements("input[type=text]"):
> input["_placeholder"] = placeholders.get(input["_name"], "")
>
> for input in signup_form.elements("input[type=password]"):
> input["_placeholder"] = pwd.get(input["_name"], '')
>
> signup_form.elements('input[type=submit]')[0]["_value"] = "Signup"
> signup_form.elements('input[type=submit]')[0]["_class"] = "btn
> btn-large btn-primary"
>
> if signup_form.process().accepted:
> response.flash = "foo"
>
> return signup_form
>
> ----------
>
> But maybe this could be done at the schema level; e.g.: utilising the
> label attribute of the Field tuple?
>
> Thanks for all suggestions,
>
> Alec Taylor
>
--
---
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.