form.errors problem.

23 views
Skip to first unread message

annet

unread,
Jul 18, 2011, 5:13:43 AM7/18/11
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.
Message has been deleted

annet

unread,
Jul 19, 2011, 1:14:08 AM7/19/11
to web2py-users
Replacing the flash with:


elif form2.errors:
print form2.errors

... and submitting the form prints this:

<Storage {'region': 'no data'}>


... which is odd, because it contains the same data as when I submit
the form after removing the autocomplete widget.


Any ideas?


Kind regards,

Annet.

annet

unread,
Jul 21, 2011, 10:58:15 AM7/21/11
to web2py-users
I mailed Pengoworks, this is their reply:

I'm not well versed in Python, but I think you're problem is that the
results from the AJAX call are not in the expected format. By default,
they're expected to be the format:

Sparta|896
Spencer|897
Spencerville|898
Spring Valley|899
Springboro|900
Springfield|901

Where each line is separated by a pipe and each line is delimited with
a line feed. You can change these values lineSeparator and
cellSeparator options. See the docs:

http://www.pengoworks.com/workshop/jquery/autocomplete_docs.txt

However, I'd really recommend migrating to the official jQuery
autocomplete plug-in as it's in active development:

http://jqueryui.com/demos/autocomplete/


Has anyone in the group been using this plug-in? How would I implement
it in the case above?


Kind regards,

Annet.
Reply all
Reply to author
Forward
0 new messages