If the attributes are supposed to apply to the HTML <form> element, then
your approach is correct. But if the attributes belong to individual
<input> and <textarea> elements, then you must use the "widget" argument of
the Field() constructor or update the widget after creation. For example:
Field('score', 'integer',
widget=lambda f, v: SQLFORM.widgets.integer.widget(f, v, _autofocus=
True))
or after defining the form:
form.custom.widget.score['_autofocus'] = True
Anthony
On Monday, March 9, 2015 at 5:53:24 PM UTC-4, Oliver Holloway wrote:
>
>
> How do I get the form to autofocus the cursor into the text box? Here's
> one of the approaches I've tried.
>
> attributes = {'_autofocus':'autofocus', '_type':'tel',
> '_autocomplete':'off', '_style':'height:80px; width:80px'}
> score_box = SQLFORM.factory(Field('score', 'integer'), **attributes)
>
> Interestingly, the autocomplete attribute is definitely getting through,
> I've tested that repeatedly. None of the other ones are.
>
> I did see the post about doing this with a form.custom.widget
> <https://groups.google.com/forum/#!searchin/web2py/autofocus/web2py/PC2nDnltGic/OiYEpQEORnkJ>
>
> setting, but couldn't figure out how to make that work in my case. I've
> also experimented with using keepvalues=True, from looking through the
> book.
>
> Any help is much appreciated. This is the last thing on my list to have
> this demo ready.
>
--
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.