Hi,
While adding custom input element to SQLFORM as described at
http://web2py.com/book/default/chapter/07#Adding-extra-form-elements-to-SQLFORM
I've found a following problem: unless there are no validator set for
custom field everything works fine. However if there's validator, for
example:
form[0].insert(INPUT(_id=id, _name=name, _type='text', _value=v,
requires=IS_NOT_EMPTY()))
form.accept will throw an exception if custom field value supplied by
user is not valid. Traceback:
Traceback (most recent call last):
File "/home/cm/.local/lib/python2.6/site-packages/web2py-1.94.6-
py2.6.egg/gluon/restricted.py", line 188, in restricted
exec ccode in environment
File "/home/cm/dev/wiki/applications/init/controllers/page.py", line
210, in <module>
File "/home/cm/.local/lib/python2.6/site-packages/web2py-1.94.6-
py2.6.egg/gluon/globals.py", line 124, in <lambda>
self._caller = lambda f: f()
File "/home/cm/dev/wiki/applications/init/controllers/page.py", line
124, in edit
if form.accepts(request.vars):
File "/home/cm/.local/lib/python2.6/site-packages/web2py-1.94.6-
py2.6.egg/gluon/sqlhtml.py", line 1042, in accepts
if self.table[key].type == 'upload' \
File "/home/cm/.local/lib/python2.6/site-packages/web2py-1.94.6-
py2.6.egg/gluon/dal.py", line 4320, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'Country'
I assume this is not what intended. form.accepts should not throw an
exception here. The problem is in this check:
for key in self.errors.keys():
if self.table[key].type == 'upload' \
key is not necessary in table (in case there are custom fields added).
This line should be changed to smth like this to make custom field
validators work:
if key in self.table and self.table[key].type ==
'upload' \