On Apr 23, 4:19 am, Joe Barnhart <
joe.barnh...@gmail.com> wrote:
> I found out a bit more regarding the problem. It seems that there is
> an ajax field validator running which requires the input be suitable
> for a "double" variable. The SQLFORM sets the "class" attribute of
> the field to "double" because that is the underlying data type.
>
> Even though my special validator is able to take strings and render
> them into a double, it never gets the chance because the ajax layer is
> rejecting all characters other than [0-9] and [.]. I need to override
> the "class" attribute on this particular field when rendered by
> SQLFORM.
It is not an ajax "validator", it is jQuery code introduced by
web2py_ajax.html using $('input.double').attr('onkeyup', ... ).
Which is why you need to change the class, as you said, to prevent
jQuery from modifying your field. The easiest way is using a widget,
before calling SQLFORM:
db.your_table.your_double.widget= lambda field, value:
INPUT(_type='text',
_id='%s_%s' %(field._tablename,
field.name),
_class='mydouble',
_name=
field.name,
value='' if not value else str(value),
requires=field.requires)