Store value in input field in a table

96 views
Skip to first unread message

pbt

unread,
Jul 12, 2016, 4:43:07 AM7/12/16
to web2py-users
in models
db.define_table('list'
                         Field('name','string'),
                        Field('location','string')
                        )

<input id="location" class="autocomplete" onFocus="geoLocation()" />
I want to store the value present in the above input field to 'location' field in table 'list'.


Mirek Zvolský

unread,
Jul 12, 2016, 5:19:30 AM7/12/16
to web2py-users
You need form and its submitting.
You can use Web2py form support, see web2py.com/book chapter 7:
   FORM,
   or SQLFORM.factory (you have to save yourselves the input value after the form validation from forms.vars into db database)
   or SQLFORM (this will save the input value automatically)

Both SQLFORM's will generate the input element, so you need learn how to modify its attributes (autofocus...) via Web2py or you can manipulate the attributes via javascript (jQuery).

With FORM you define all elements in the view. So manipulating with field attributes is easy, but you have more work to do. + you need save form.vars too.





Dne úterý 12. července 2016 10:43:07 UTC+2 pbt napsal(a):

pbt

unread,
Jul 12, 2016, 6:15:27 AM7/12/16
to web2py-users
I know how to generate input fields from form. My doubt is I want to add an event 'onFocus' to that field. How to do that using SQLFORM.factory

Massimo Di Pierro

unread,
Jul 12, 2016, 8:34:53 AM7/12/16
to web2py-users
form.element(_name='location')['onfocus'] = 'geoLocation()'

BUT

You should really do this in the view:

<script>
jQuery(function() {
   jQuery('[name=location]').focus(geoLocation);
});
</script>

pbt

unread,
Jul 12, 2016, 11:06:58 AM7/12/16
to web2py-users
I added these lines in my view
<script>
jQuery(function() {
   jQuery('[name=location]').focus(geolocate);
});
</script>

But it is not working.
What I am actually trying to do is while filling field 'location',it should give the suggestions automatically fetched from google maps.
The suggestions are coming when I write this.
<input id="autocomplete" placeholder="Enter your address" onFocus="geolocate()" type="text"></input>

What am I doing wrong??

pbt

unread,
Jul 12, 2016, 11:14:16 AM7/12/16
to web2py-users
How to add id to the field 'location' using jquery in view. Because my js function also requires the field to have id="autocomplete"


On Tuesday, July 12, 2016 at 6:04:53 PM UTC+5:30, Massimo Di Pierro wrote:

Joe Lwe

unread,
Jan 9, 2017, 11:39:01 PM1/9/17
to web2py-users
Hi.. I have the same challange, did u get a solution.. if yes kindly share.. but I guess the coordinates have to be stored in location field of the table.

Thanks

Leonel Câmara

unread,
Jan 11, 2017, 1:16:34 PM1/11/17
to web2py-users
Can we see the entire controller and view where you're trying this?

Reply all
Reply to author
Forward
0 new messages