[web2py] Re: form.errors problem.

2011-07-21 Thread annet
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.


[web2py] Re: form.errors problem.

2011-07-18 Thread annet
By the way, regions are defined like this:
Field('regio',length=2,default='',notnull=True,unique=True) and the
field regio contains regions between 00 and 99.

Maybe this is what's causing the problem???


[web2py] Re: form.errors problem.

2011-07-18 Thread annet
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.


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Massimo Di Pierro
Because onfailure

def validateTerms(form):
if form.vars.terms != 'agree':
form.errors.terms = 'You must agree to the terms.'

must be

def validateTerms(form):
if request.vars.terms != 'agree':
form.errors.terms = 'You must agree to the terms.'

as the request.vars has not yet been copied into form.vars I
think.

On Apr 14, 8:18 am, Brian Will brian.thomas.w...@gmail.com wrote:
 I'm trying to add a checkbox that must be ticked to an update SQLFORM,
 but I'm getting an internal error.

 Here's the create form that works fine with an added checkbox:

     form = SQLFORM(db.job_post, submit_button='Post Job',
 formstyle='table2cols',
         fields=['poster_name', 'poster_email', 'poster_phone',
 'zipcode', 'job_type', 'job_title', 'job_description'],
         _id='postjob',
         _class='form2col'
     )
     form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
 service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
 _type='checkbox', _style=margin: 0px 0px 4px 14px  # add
 checkbox

     def validateTerms(form):
         if form.vars.terms != 'agree':
             form.errors.terms = 'You must agree to the terms.'

     if form.accepts(request.vars, session, onvalidation={'onsuccess':
 validateTerms, 'onfailure': validateTerms}):
          # bla bla

 Now on another page here's virtually the same thing but an update
 form:

 form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
 formstyle='table2cols',
             fields=['poster_name', 'poster_email', 'poster_phone',
 'zipcode', 'job_type', 'job_title', 'job_description'],
             _id='postjob',
             _class='form2col'
         )
         form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
 of service', _href=URL('terms'))), INPUT(_name='terms',
 _value='agree', _type='checkbox', _style=margin: 0px 0px 4px
 14px  # add checkbox

         def validateTerms(form):
             if form.vars.terms != 'agree':
                 form.errors.terms = 'You must agree to the terms.'

         if form.accepts(request.vars, session,
 onvalidation={'onsuccess': validateTerms, 'onfailure':
 validateTerms}):
                       # bla bla

 And here's the ticket I get with this second form:

 Traceback (most recent call last):
   File /home/www-data/web2py/gluon/restricted.py, line 188, in
 restricted
     exec ccode in environment
   File /home/www-data/web2py/applications/staging/controllers/
 default.py, line 329, in module
   File /home/www-data/web2py/gluon/globals.py, line 124, in lambda
     self._caller = lambda f: f()
   File /home/www-data/web2py/applications/staging/controllers/
 default.py, line 119, in post_edit
     if form.accepts(request.vars, session, onvalidation={'onsuccess':
 validateTerms, 'onfailure': validateTerms}):
   File /home/www-data/web2py/gluon/sqlhtml.py, line 1042, in accepts
     if self.table[key].type == 'upload' \
   File /home/www-data/web2py/gluon/dal.py, line 4320, in __getitem__
     return dict.__getitem__(self, str(key))
 KeyError: 'terms'

 Looking at sqlhtml.py line 1042, I see there's a check done for update
 forms that involves looking for every entry in self.errors in
 self.table, which of course won't be found here because my checkbox is
 not part of the table.

 If I comment out the assignment to form.errors.terms, I don't get this
 error, but of course then I don't get the validation I want. Also, I
 strangely then get a 'no data' error message for the first field when
 I visit the page but no such error when I submit the form. If I remove
 the onvalidation arg from accepts, this error goes away entirely.

 So any ideas? Am I doing things wrong or is there some bug here?


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
No, form.vars and request.vars both work the same there. (Should I be
using request instead anyway?) The internal error stems from adding
'terms' to form.errors, which then gets looked up as if 'terms' is a
field in my table, which it's not. Look at sqlhtml.py line 1042.

So am I doing this in a way that's supposed to work? Is this an edge
case just not accounted for yet?

On Apr 14, 6:30 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 Because onfailure

 def validateTerms(form):
             if form.vars.terms != 'agree':
                 form.errors.terms = 'You must agree to the terms.'

 must be

 def validateTerms(form):
             if request.vars.terms != 'agree':
                 form.errors.terms = 'You must agree to the terms.'

 as the request.vars has not yet been copied into form.vars I
 think.

 On Apr 14, 8:18 am, Brian Will brian.thomas.w...@gmail.com wrote:







  I'm trying to add a checkbox that must be ticked to an update SQLFORM,
  but I'm getting an internal error.

  Here's the create form that works fine with an added checkbox:

      form = SQLFORM(db.job_post, submit_button='Post Job',
  formstyle='table2cols',
          fields=['poster_name', 'poster_email', 'poster_phone',
  'zipcode', 'job_type', 'job_title', 'job_description'],
          _id='postjob',
          _class='form2col'
      )
      form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
  service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
  _type='checkbox', _style=margin: 0px 0px 4px 14px  # add
  checkbox

      def validateTerms(form):
          if form.vars.terms != 'agree':
              form.errors.terms = 'You must agree to the terms.'

      if form.accepts(request.vars, session, onvalidation={'onsuccess':
  validateTerms, 'onfailure': validateTerms}):
           # bla bla

  Now on another page here's virtually the same thing but an update
  form:

  form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
  formstyle='table2cols',
              fields=['poster_name', 'poster_email', 'poster_phone',
  'zipcode', 'job_type', 'job_title', 'job_description'],
              _id='postjob',
              _class='form2col'
          )
          form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
  of service', _href=URL('terms'))), INPUT(_name='terms',
  _value='agree', _type='checkbox', _style=margin: 0px 0px 4px
  14px  # add checkbox

          def validateTerms(form):
              if form.vars.terms != 'agree':
                  form.errors.terms = 'You must agree to the terms.'

          if form.accepts(request.vars, session,
  onvalidation={'onsuccess': validateTerms, 'onfailure':
  validateTerms}):
                        # bla bla

  And here's the ticket I get with this second form:

  Traceback (most recent call last):
    File /home/www-data/web2py/gluon/restricted.py, line 188, in
  restricted
      exec ccode in environment
    File /home/www-data/web2py/applications/staging/controllers/
  default.py, line 329, in module
    File /home/www-data/web2py/gluon/globals.py, line 124, in lambda
      self._caller = lambda f: f()
    File /home/www-data/web2py/applications/staging/controllers/
  default.py, line 119, in post_edit
      if form.accepts(request.vars, session, onvalidation={'onsuccess':
  validateTerms, 'onfailure': validateTerms}):
    File /home/www-data/web2py/gluon/sqlhtml.py, line 1042, in accepts
      if self.table[key].type == 'upload' \
    File /home/www-data/web2py/gluon/dal.py, line 4320, in __getitem__
      return dict.__getitem__(self, str(key))
  KeyError: 'terms'

  Looking at sqlhtml.py line 1042, I see there's a check done for update
  forms that involves looking for every entry in self.errors in
  self.table, which of course won't be found here because my checkbox is
  not part of the table.

  If I comment out the assignment to form.errors.terms, I don't get this
  error, but of course then I don't get the validation I want. Also, I
  strangely then get a 'no data' error message for the first field when
  I visit the page but no such error when I submit the form. If I remove
  the onvalidation arg from accepts, this error goes away entirely.

  So any ideas? Am I doing things wrong or is there some bug here?


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Massimo Di Pierro
Please open an issue in google code and I will fix this asap.

On Apr 14, 8:56 am, Brian Will brian.thomas.w...@gmail.com wrote:
 No, form.vars and request.vars both work the same there. (Should I be
 using request instead anyway?) The internal error stems from adding
 'terms' to form.errors, which then gets looked up as if 'terms' is a
 field in my table, which it's not. Look at sqlhtml.py line 1042.

 So am I doing this in a way that's supposed to work? Is this an edge
 case just not accounted for yet?

 On Apr 14, 6:30 am, Massimo Di Pierro massimo.dipie...@gmail.com
 wrote:







  Because onfailure

  def validateTerms(form):
              if form.vars.terms != 'agree':
                  form.errors.terms = 'You must agree to the terms.'

  must be

  def validateTerms(form):
              if request.vars.terms != 'agree':
                  form.errors.terms = 'You must agree to the terms.'

  as the request.vars has not yet been copied into form.vars I
  think.

  On Apr 14, 8:18 am, Brian Will brian.thomas.w...@gmail.com wrote:

   I'm trying to add a checkbox that must be ticked to an update SQLFORM,
   but I'm getting an internal error.

   Here's the create form that works fine with an added checkbox:

       form = SQLFORM(db.job_post, submit_button='Post Job',
   formstyle='table2cols',
           fields=['poster_name', 'poster_email', 'poster_phone',
   'zipcode', 'job_type', 'job_title', 'job_description'],
           _id='postjob',
           _class='form2col'
       )
       form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
   service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
   _type='checkbox', _style=margin: 0px 0px 4px 14px  # add
   checkbox

       def validateTerms(form):
           if form.vars.terms != 'agree':
               form.errors.terms = 'You must agree to the terms.'

       if form.accepts(request.vars, session, onvalidation={'onsuccess':
   validateTerms, 'onfailure': validateTerms}):
            # bla bla

   Now on another page here's virtually the same thing but an update
   form:

   form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
   formstyle='table2cols',
               fields=['poster_name', 'poster_email', 'poster_phone',
   'zipcode', 'job_type', 'job_title', 'job_description'],
               _id='postjob',
               _class='form2col'
           )
           form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
   of service', _href=URL('terms'))), INPUT(_name='terms',
   _value='agree', _type='checkbox', _style=margin: 0px 0px 4px
   14px  # add checkbox

           def validateTerms(form):
               if form.vars.terms != 'agree':
                   form.errors.terms = 'You must agree to the terms.'

           if form.accepts(request.vars, session,
   onvalidation={'onsuccess': validateTerms, 'onfailure':
   validateTerms}):
                         # bla bla

   And here's the ticket I get with this second form:

   Traceback (most recent call last):
     File /home/www-data/web2py/gluon/restricted.py, line 188, in
   restricted
       exec ccode in environment
     File /home/www-data/web2py/applications/staging/controllers/
   default.py, line 329, in module
     File /home/www-data/web2py/gluon/globals.py, line 124, in lambda
       self._caller = lambda f: f()
     File /home/www-data/web2py/applications/staging/controllers/
   default.py, line 119, in post_edit
       if form.accepts(request.vars, session, onvalidation={'onsuccess':
   validateTerms, 'onfailure': validateTerms}):
     File /home/www-data/web2py/gluon/sqlhtml.py, line 1042, in accepts
       if self.table[key].type == 'upload' \
     File /home/www-data/web2py/gluon/dal.py, line 4320, in __getitem__
       return dict.__getitem__(self, str(key))
   KeyError: 'terms'

   Looking at sqlhtml.py line 1042, I see there's a check done for update
   forms that involves looking for every entry in self.errors in
   self.table, which of course won't be found here because my checkbox is
   not part of the table.

   If I comment out the assignment to form.errors.terms, I don't get this
   error, but of course then I don't get the validation I want. Also, I
   strangely then get a 'no data' error message for the first field when
   I visit the page but no such error when I submit the form. If I remove
   the onvalidation arg from accepts, this error goes away entirely.

   So any ideas? Am I doing things wrong or is there some bug here?


[web2py] Re: form.errors problem when adding inputs to updating SQLFORM

2011-04-14 Thread Brian Will
Done. Thanks Massimo, and for all your hard work.

On Apr 14, 7:29 am, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 Please open an issue in google code and I will fix this asap.

 On Apr 14, 8:56 am, Brian Will brian.thomas.w...@gmail.com wrote:







  No, form.vars and request.vars both work the same there. (Should I be
  using request instead anyway?) The internal error stems from adding
  'terms' to form.errors, which then gets looked up as if 'terms' is a
  field in my table, which it's not. Look at sqlhtml.py line 1042.

  So am I doing this in a way that's supposed to work? Is this an edge
  case just not accounted for yet?

  On Apr 14, 6:30 am, Massimo Di Pierro massimo.dipie...@gmail.com
  wrote:

   Because onfailure

   def validateTerms(form):
               if form.vars.terms != 'agree':
                   form.errors.terms = 'You must agree to the terms.'

   must be

   def validateTerms(form):
               if request.vars.terms != 'agree':
                   form.errors.terms = 'You must agree to the terms.'

   as the request.vars has not yet been copied into form.vars I
   think.

   On Apr 14, 8:18 am, Brian Will brian.thomas.w...@gmail.com wrote:

I'm trying to add a checkbox that must be ticked to an update SQLFORM,
but I'm getting an internal error.

Here's the create form that works fine with an added checkbox:

    form = SQLFORM(db.job_post, submit_button='Post Job',
formstyle='table2cols',
        fields=['poster_name', 'poster_email', 'poster_phone',
'zipcode', 'job_type', 'job_title', 'job_description'],
        _id='postjob',
        _class='form2col'
    )
    form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms of
service', _href=URL('terms'))), INPUT(_name='terms', _value='agree',
_type='checkbox', _style=margin: 0px 0px 4px 14px  # add
checkbox

    def validateTerms(form):
        if form.vars.terms != 'agree':
            form.errors.terms = 'You must agree to the terms.'

    if form.accepts(request.vars, session, onvalidation={'onsuccess':
validateTerms, 'onfailure': validateTerms}):
         # bla bla

Now on another page here's virtually the same thing but an update
form:

form = SQLFORM(db.job_post, job.id, submit_button='Update Job',
formstyle='table2cols',
            fields=['poster_name', 'poster_email', 'poster_phone',
'zipcode', 'job_type', 'job_title', 'job_description'],
            _id='postjob',
            _class='form2col'
        )
        form[0].insert(-2, TR(SPAN(LABEL('I agree to the ', A('terms
of service', _href=URL('terms'))), INPUT(_name='terms',
_value='agree', _type='checkbox', _style=margin: 0px 0px 4px
14px  # add checkbox

        def validateTerms(form):
            if form.vars.terms != 'agree':
                form.errors.terms = 'You must agree to the terms.'

        if form.accepts(request.vars, session,
onvalidation={'onsuccess': validateTerms, 'onfailure':
validateTerms}):
                      # bla bla

And here's the ticket I get with this second form:

Traceback (most recent call last):
  File /home/www-data/web2py/gluon/restricted.py, line 188, in
restricted
    exec ccode in environment
  File /home/www-data/web2py/applications/staging/controllers/
default.py, line 329, in module
  File /home/www-data/web2py/gluon/globals.py, line 124, in lambda
    self._caller = lambda f: f()
  File /home/www-data/web2py/applications/staging/controllers/
default.py, line 119, in post_edit
    if form.accepts(request.vars, session, onvalidation={'onsuccess':
validateTerms, 'onfailure': validateTerms}):
  File /home/www-data/web2py/gluon/sqlhtml.py, line 1042, in accepts
    if self.table[key].type == 'upload' \
  File /home/www-data/web2py/gluon/dal.py, line 4320, in __getitem__
    return dict.__getitem__(self, str(key))
KeyError: 'terms'

Looking at sqlhtml.py line 1042, I see there's a check done for update
forms that involves looking for every entry in self.errors in
self.table, which of course won't be found here because my checkbox is
not part of the table.

If I comment out the assignment to form.errors.terms, I don't get this
error, but of course then I don't get the validation I want. Also, I
strangely then get a 'no data' error message for the first field when
I visit the page but no such error when I submit the form. If I remove
the onvalidation arg from accepts, this error goes away entirely.

So any ideas? Am I doing things wrong or is there some bug here?