I think the current autocomplete is incompatible with SQLFORM.factory, but don't quote me on this.
On Apr 14, 1:17 pm, annet <annet.verm...@gmail.com> wrote: > I have the following function: > > def index(): > form1=SQLFORM.factory( > > Field('what',widget=SQLFORM.widgets.autocomplete(request,db.companykeyword.word)) > > Field('city',widget=SQLFORM.widgets.autocomplete(request,db.address.city))) > form2=SQLFORM.factory( > > Field('what',widget=SQLFORM.widgets.autocomplete(request,db.companykeyword.word)), > > Field('zip',widget=SQLFORM.widgets.autocomplete(request,db.zip.region))) > form3=[] > if form1.accepts(request.vars,session,formname='form1'): > > redirect(URL(r=request,c='locator',f='city',args=[request.vars.what,request.vars.city])) > if form2.accepts(request.vars,session,formname='form2'): > > redirect(URL(r=request,c='locator',f='zip',args=[request.vars.what,request.vars.region])) > return dict(form1=form1,form2=form2,form3=form3) > > The problem is my struggle with the logic of the city function in the > locator controller. If form1 is filled in and submitted, the index > function above redirects to the city function in the locator > controller. The city function again defines form1 and depending on > whether form1 has been submitted from within the index function or the > city function the database should be queried for results. > > def city(): > form=SQLFORM.factory( > > Field('what',widget=SQLFORM.widgets.autocomplete(request,db.companykeyword.word)) > > Field('city',widget=SQLFORM.widgets.autocomplete(request,db.address.city))) > if request.args: > > rows=db((..)&(db.companykeyword.word==request.args(0))&(db.address.city==request.args(1))) > .select(db.company.ALL,db.address.ALL) > if form.accepts(request.vars,session,keepvalues=True): > > rows=db((..)&(db.companykeyword.word==request.vars.what)&(db.address.city==request.vars.city)) > .select(db.company.ALL,db.address.ALL) > return dict(form=form,rows=rows) > > Now, when I enter coaching Amsterdam in form1 in the index view, the > url reads like: > > http://127.0.0.1:8000/init/locator/city/coaching/Amsterdam > > ... and the results are displayed correctly. When I enter coaching > Utrecht in the form in the city view, the url still reads like: > > http://127.0.0.1:8000/init/locator/city/coaching/Amsterdam > > ... and no results are displayed (which is correct). Then, when I > enter mentoring Amsterdam in the form in the city view, the url > doesn't change and the correct results are displayed. > > I have no idea why the url keeps the args and why the form seems to > work well although the args are still there. I hope one of you can > help me solve this problem. > > Kind regards, > > Annet.