adding onFocus event to a field of an sql form

Yametazamwa mara 66
Ruka hadi kwenye ujumbe wa kwanza ambao haujasomwa

pbt

hayajasomwa,
12 Jul 2016, 04:18:2112/07/2016
kwa 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

hayajasomwa,
12 Jul 2016, 10:38:3912/07/2016
kwa 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

hayajasomwa,
12 Jul 2016, 11:26:0012/07/2016
kwa 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

hayajasomwa,
12 Jul 2016, 11:40:4012/07/2016
kwa 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

hayajasomwa,
12 Jul 2016, 14:27:3812/07/2016
kwa web2py-users
So, is this question a duplicate of this one?


-Jim

pbt

hayajasomwa,
12 Jul 2016, 16:05:3612/07/2016
kwa 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.
Jibu wote
Mjibu mchapishaji
Sambaza
Ujumbe 0 mpya