annet
unread,Jul 18, 2011, 5:13:43 AM7/18/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web2py-users
I've been struggling with this problem for days now and still don't
see why the form contains an error. This is the relevant part of the
function:
def index():
...
form1=SQLFORM.factory(
Field('key1',label='wat',length=72,requires=IS_NOT_EMPTY(),\
widget=lambda self,
value:INPUT(_id='key1',_name='key1',_class='ac_input',_type='text',requires=self.requires)),
Field('city',label='plaats',length=42,requires=IS_NOT_EMPTY(),
\
widget=lambda self,
value:INPUT(_id='city',_name='city',_class='ac_input',_type='text',requires=self.requires)))
form2=SQLFORM.factory(
Field('key2',label='wat',length=72,requires=IS_NOT_EMPTY(),\
widget=lambda self,
value:INPUT(_id='key2',_name='key2',_class='ac_input',_type='text',requires=self.requires)),
Field('region',label='regio',requires=IS_NOT_EMPTY(),\
widget=lambda self,
value:INPUT(_id='zipStandard',_name='zipStandard',_class='ac_input',_type='text',requires=self.requires)))
if form1.accepts(request.vars,session,formname='form1'):
session.key1=request.vars.key1
session.city=request.vars.city
redirect(URL(r=request,c='locator',f='city'))
elif form1.errors:
response.flash='response.flash_searcherror form1'
if form2.accepts(request.vars,session,formname='form2'):
session.key2=request.vars.key2
session.region=request.vars.region
redirect(URL(r=request,c='locator',f='zipcode'))
elif form2.errors:
response.flash='response.flash_searcherror form2'
return dict(form1=form1,form2=form2)
Form1 does work, form2 does work when I remove this part of the code:
widget=lambda self,
value:INPUT(_id='zipStandard',_name='zipStandard',_class='ac_input',_type='text',requires=self.requires)
It is based on the Pengoworks autocomplete, in web2py_ajax.html I put:
response.files.insert(6,URL(r=request,c='static',f='init/css/
jquery.autocomplete.css'))
response.files.insert(7,URL(r=request,c='static',f='init/js/
jquery.autocomplete.js'))
$('#zipStandard').autocomplete("/init/handlers/zipStandardAC",
{maxItemsToShow:12});
... and in the handlers controller:
def zipStandardAC():
q=''
if request.vars:
q=request.vars.q
if not q:
return q
rows=db(db.postcoderegio.regio.like('%s%%'%q.capitalize()))\
.select(db.postcoderegio.regio,distinct=True,orderby=db.postcoderegio.regio)
r=''
for row in rows:
r='%s%s\n'%(r,row.regio)
return r
... the function queries this table:
db.define_table('postcoderegio',
Field('regio',length=2,default='',notnull=True,unique=True),
Field('codemin',type='integer',default='',notnull=True,unique=True),
Field('codemax',type='integer',default='',notnull=True,unique=True),
Field('provincie_id',
db.provincie,default='',notnull=True,ondelete='RESTRICT'),
migrate=False)
db.postcoderegio.regio.requires=[IS_LENGTH(2,error_message='lengte
overschreidt 2
tekens'),IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'postcoderegio.regio',error_message='regio
al in database')]
The autocomplete bit works, however, when I submit the form I get
"response.flash_searcherror form2" flashed. I have no idea why, I hope
one of you does ...
Kind regards,
Annet.