On Thursday, March 2, 2017 at 5:26:38 AM UTC-8, Anthony wrote: > > For an SQLFORM(), things are a little trickier, because the **attributes >> applies to the whole FORM object, and can't be directed to the input field. >> So I tried using >> form.elements(input, _id=table_field, replace=lambda i: i[0:-2] + >> "autofocus" + i[-1]) >> >> but i is a gluon.html.INPUT object and not sliceable (the slices become >> empty strings); there is also a ticket for trying to concatenate a string >> to a list, just to keep me confused. Do I need to use javascript to set >> the focus? >> > > You don't need to replace the input -- just update it: > > form.element(...)['_autofocus'] = True >
Just to keep things interesting, I tried this with a form from SQLFORM.factory() (used as a LOAD item). It keeps ending up in a ticket, File "C:/Users/Dave/web2py_win/web2py_win 2.14.6/web2py/applications/badlist/controllers/default.py" <http://127.0.0.1:8000/admin/default/edit/badlist/controllers/default.py>, line 46, in getpic form.element(input, _id="no_table_image_url")['_autofocus'] = True File "C:\Users\Dave\web2py_win\web2py_win 2.14.6\web2py\gluon\html.py", line 1200, in element elements = self.elements(*args, **kargs) File "C:\Users\Dave\web2py_win\web2py_win 2.14.6\web2py\gluon\html.py", line 1104, in elements args = [a.strip() for a in args[0].split(',')] AttributeError: 'builtin_function_or_method' object has no attribute 'split' *File C:\Users\Dave\web2py_win\web2py_win 2.14.6\web2py\gluon\html.py in elements at line 1104* Function argument list (self=<gluon.sqlhtml.SQLFORM object>, *args=(<built-in function input>,), **kargs={'_id': 'no_table_image_url', 'first_only': True}) 1103. 1104. 1105. 1106. 1107. 1108. >>> b = a.elements('span.efg', find_text=re.compile('x|y|z'), replace='hello') >>> print a <div><div><span class="abc">x</span><div><span class="efg">hello</span><span class="abc">z</span></div></div></div> """ if len(args) == 1: args = [a.strip() for a in args[0].split(',')] > > But if it is a SQLFORM, a better approach is probably to change the widget > associated with the DAL Field: > > db.mytable.myfield.widget = lambda f, v: SQLFORM.widgets.string.widget(f, > v, _autofocus=True) > > If you always want autofocus set for that field, you can do the above > within the DAL table definition. > > I tried setting the widget in the factoryfield def, and that doesn't seem to have an error, but doesn't autofocus. When the LOAD'ed form is submitted, I'm hoping to have the focus be on the factoryfield; when loading the page, the focus should be on the starting field of the main form (which is just SQLFORM()'d). Anthony > > >> >> /dps >> >> >> (It's me again) /dps -- 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.

