I've got this form:
form = SQLFORM.factory(
Field('tag', length=128, requires=[IS_IN_DB(db, 'tag.name', '%(name)s',
error_message='Tag not in database')]),
Field('locality', length=64, requires=[IS_IN_DB(db, 'locality.name',
'%(name)s',
error_message='Locality
not in database')]),
hideerror=True, separator='', formstyle=bootstrap3)
Fields tag and locality are autocomplete fields based on jQueryUI.
In the view I've got:
<script type="text/javascript">
$(function() {$("#no_table_tag").autocomplete({source: "{{=URL('jqueryui',
'nodetag_autocomplete')}}",minLength: 2});});
$(function() {$("#no_table_locality").autocomplete({source:
"{{=URL('jqueryui', 'addresslocality_autocomplete')}}",minLength: 2});});
</script>
And in a controller called jqueryui:
def addresslocality_autocomplete():
rows =
db(db.address.locality.like(request.vars.term+'%')).select(db.address.locality,
distinct=True,
orderby=db.address.locality).as_list()
result = [r['locality'] for r in rows]
return response.json(result)
def nodetag_autocomplete():
rows =
db(db.node_tag.tag.like(request.vars.term+'%')).select(db.node_tag.tag,
distinct=True,
orderby=db.node_tag.tag).as_list()
result = [r['tag'] for r in rows]
return response.json(result)
What I want is, make the autocomplete options for field locality depend on
the value of field tag.
Coded with the constant tag 'Personal coaching', something like"
In the view:
$(function() {
$("#no_table_locality").autocomplete({source: "{{=URL('jqueryui',
'addresslocality_autocomplete')}} + '/' + 'Personal coaching' ", minLength:
2})
;});
In the jqueryui controller:
rows = db((db.node_tag.tag=='Personal coaching') &
(db.node_tag.nodeID==db.address.nodeID) &
(db.address.locality.like(request.vars.term+'%'))).select(db.address.locality,
distinct=True,
orderby=db.address.locality).as_list()
In the view I tried:
var x = document.getElementById("no_table_tag").value;
and replace '/' + 'Personal coaching' with '/' + x
but that doesn't work.
In the jqueryui controller this doesn't work either:
(db.node_tag.tag==request.args(0))
Is there a way to solve this issue or is it just not possible.
Regards,
Annet
--
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.