adding onFocus event to a field of an sql form

66 views
Skip to first unread message

pbt

unread,
Jul 12, 2016, 4:18:21 AM7/12/16
to web2py-users
In models

db.define_table('list',
Field('name', 'string'),
Field('location', 'string'))

In controller
def list():
form = SQLFORM.factory(
Field('name',label='Name',requires=IS_NOT_EMPTY()),
Field('location',label='Location',requires=IS_NOT_EMPTY()))

          
In default/list.html

{{=form}}


I want to execute an event onFocus="myFunction()" for field 'location' present in table 'list'.How to do it? Somebody help me.

Jim S

unread,
Jul 12, 2016, 10:38:39 AM7/12/16
to web2py-users
Here is what I've added to my layout.html so that all my pages automatically position the cursor to the first input field available that doesn't have the .filter class applied to it:

    <script type="text/javascript">
        $
(document).ready(function () {
            $
('form:not(.filter) :input:visible:first').focus().select();
   
</script>

-Jim

pbt

unread,
Jul 12, 2016, 11:26:00 AM7/12/16
to web2py-users
I do not want the input field 'location' to be focussed automatically. I want to execute a myFunction() when input field 'location' with id = 'autocomplete' is focused .

Ron Chatterjee

unread,
Jul 12, 2016, 11:40:40 AM7/12/16
to web...@googlegroups.com
You can also use a "custom form" on table list and use this:


As you build the form, just stick the classes there where you want the focus to be.

Jim S

unread,
Jul 12, 2016, 2:27:38 PM7/12/16
to web2py-users
So, is this question a duplicate of this one?


-Jim

pbt

unread,
Jul 12, 2016, 4:05:36 PM7/12/16
to web2py-users
@JIM S
Yes,both questions are same.I am finding two different methods for this question.So,I asked same question in two different ways.
1)writing input field manually in view with onfocus="myfunction()" and then storing in database.
2)Manipulating something in controller SQLFORM.factory() to add onfocus="myfunction()" event in that particular field.
Reply all
Reply to author
Forward
0 new messages