Denes,
This is what I got so far,
From your reply on Ma8 8, 11:32 pm:
I put the jquery.autocomplete.js and jquery.autocomplete.css into
their respective folders in the static folder of my application and
added the following links to my modified copy of web2py_ajax.html:
<link href="{{=URL(r=request,c='static',f='css/
jquery.autocomplete.css')}}" rel="stylesheet" type="text/css"
media="screen" charset="utf-8" />
<script src="{{=URL(r=request,c='static',f='scripts/
jquery.autocomplete.js')}}" type="text/javascript"></script>
Then, in the same file I inserted the following line of code into the $
(document).ready(function() {}
$('#city').autocomplete("/b2c/handlers/cityAC",{maxItemsToShow:12});
I changed the form_factory form in my controller to read like:
form=form_factory(SQLField('plaatsnaam',
label='Type een plaatsnaam',
requires=IS_NOT_EMPTY(),
widget=lambda self, value:TAG[''](
INPUT(_id="plaatsnaam",
_name="plaatsnaam",
_class=”ac_input”,
_type="text")
)))
From your post on May 9, 2:42 pm:
Question 1) in your post you say that when you type something into the
INPUT field that triggers the autocomplete,... How does the
application know it is an autocomplete field, (_class="ac_input" ?)
Question 2) then you continue ... The autocomplete creates an ajax
call to the supplied handler function (in my case /handlers/cityAC the
first parameter in $('#city').autocomplete("/b2c/handlers/cityAC",
{maxItemsToShow:12});) sending it whatever was typed in a parameter
named q. I am using the pengoworks plugin so I guess its q in my
application too?
From your post on May 9, 4:22 pm:
In my controller 'handlers' I have the function cityAC (taken from
your example):
def cityAC()
q=""
if request.vars:
q=request.vars.q
if not q:
return q
rows=db (db.adres.plaatsnaam.like(request.vars.q.captitalize()+'%s%
%'%q))./
select(db.adres.plaatsnaam,distinct=True)
r=""
for row in rows:
r='%s%s'%(r,row.option)
return r
Question 3) In your post on May 8, 11:32 I read the following lines:
You can also have cascaded fields by adding:
...maxItemsToShow: 10, onItemSelect: function(itm) { ... the code to
modify the cascaded fields here ...} } ) ;
I defined the autocompletes and their handlers in the controller,
passing them in the response dict along with a function that will
create the JS code in myajax.html view:
in ctl: return dict{ ACs=ACs, ACfunc=ACfunc, ...}
in myajax view (loaded by mylayout.html):
{{try
ACs
except NameError:
pass
else:}}
{{=XML(ACfunc(ACs,request))}}
{{pass}}
The ACfunc() returns a string with all the jQuery code for each
autocomplete:
$("#field_id").autocomplete(...) ;
But you can just place the JS code directly there using:
$("#{{=field_id}}").autocomplete(...) ;
I haven't got a clue where to put these lines of code in my
application and what their purpose is. I hope you will help me getting
this auto-complete field to work, thanks for your time and effort.
Annet.