ah, my bad, the position order is not right in the views.
e.g. correct
*views/default/test.html*
{{extend 'layout.html'}}
{{=btn }}
{{=DIV(_id='demo') }}
{{=scr }}
another example that work using javascript and form :
controllers/default.py
def again():
t_name = 'any_tbl' # just for more readable because SQLFORM.factory
latitude = 'any_fld_1'
longitude = 'any_fld_2'
f_id = lambda f, t = t_name: '%s_%s' % (t, f) # return id of html
INPUT-element corresponding to field name
btn = BUTTON('Try It', _type = "button", _onclick = """getLocation()"""
)
scr = SCRIPT("""
$(document).ready(getLocation );
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
$('#%s').val(position.coords.latitude);
$('#%s').val(position.coords.longitude);
return
}
""" % (f_id(latitude), f_id(longitude) )
)
frm=SQLFORM.factory(
Field(latitude, 'string', comment = DIV(btn) ),
Field(longitude, 'string'),
table_name = t_name)
if frm.process().accepted:
response.flash = frm.vars[latitude]+','+frm.vars[longitude]
return dict(frm = frm, scr = scr)
best regards,
stifan
--
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.