On Saturday, March 11, 2017 at 7:25:49 AM UTC-8, Anthony wrote:
>
>
> 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'
>>
>>
> Should be form.element('input', ...), not form.element(input, ...).
>  
>

Partial 'doh!'  -- that change indeed stops the flow of tickets.  Does not 
help focus (focus is not on an input in either the main form or the LOAD'ed 
form; I'm not quite sure where it is).


>>
>> I tried setting the widget in the factoryfield def, and that doesn't seem 
>> to have an error, but doesn't autofocus.  
>>
>
As above, not sure where the focus is.  Hitting tab or shift-tab may 
highlight the stuff on the menu or maybe the links.  I can't always see the 
cursor until I've moved it a few times.
 

> 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). [Edit:] Normal loading, 
>> and submitting of the main form, does indeed put focus on that starting 
>> field of the main form.
>>
>
> Need to see some code.
>
> Anthony
>

Views are pretty much from the Welcome app, with the toolbar removed.

in main view (default/index.html)

{{left_sidebar_enabled,right_sidebar_enabled=False,('message' in globals
())}}
{{extend 'layout.html'}}
[usual block header stuff]
[A couple of strings, with each having an {{=A(...)}} helper.]
{{=form}}
{{=getter}}



LOAD view: (default/getitem.load)
{{if len(response._vars)==1:}}
{{=response._vars.values()[0]}}
{{pass}}




default.py/index():
    [housekeeping for PostDate]
    form = SQLFORM(db.mylist)
    if form.process().accepted:
        response.flash = T("Thank you!")
    elif form.errors:
        response.flash = T("Please correct the errors in the form")
    else:
        response.flash = T("Please fill out the form")
    return dict(form=form, getter=LOAD(url=URL(r=request,f='getitem.load'),
ajax=True))



default.py/getitem():
    form = SQLFORM.factory(
        Field('item', requires=IS_NOT_EMPTY(), widget = lambda f, v: SQLFORM
.widgets.string.widget(f, v, _autofocus=True)) ,
        Field('tags'))
    # form.element("input", _id="no_table_image_url")['_autofocus'] = True
    if form.process().accepted:
        response.flash = form.vars.image_url + ' accepted'
        session.your_image = form.vars.image_url
        details=figureoutdetails(form.vars.item)
        newrow={'item': form.vars.item, 'details': details, 'tags' : form.
vars.tags,
                'PostDate':str(request.now.year)+"-"+str(request.now.month)+
"-"+str(request.now.day)}
        db.myitem.insert(**newrow)
    elif form.errors:
        response.flash = 'form has errors'
    return dict(form=form)



(Yeah, both tables keep track of the posting date of their contents.  I 
don't think it's an OCD symptom, though.)

I may be asking for moon ... expecting a "junior" autofocus to be "scoped" 
to the DIV it's form is loaded in.  Browsers may instead consider 2 
autofoci to be undefined behavior.  In which case, turning to javascript 
may be my best choice.  I've got my fingers crossed, though.

/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.

Reply via email to