zopefoundation / z3c.form

An advanced form and widget framework for Zope 3
Other
9 stars 39 forks source link

Float validator fails on more that 3 digits after decimal separator #80

Open hvelarde opened 6 years ago

hvelarde commented 6 years ago

I have a couple of fields defined this way:

class IPin(model.Schema):
    """A Pin."""
    ...
    latitude = schema.Float(
        title=_(u'label_latitude', default=u'Latitude'),
        required=True,
        default=0.0,
    )

    longitude = schema.Float(
        title=_(u'label_longitude', default=u'Longitude'),
        required=True,
        default=0.0,
    )

the validator accepts a number like -12,345 but fails with something like -12,3456 with:

The entered value is not a valid decimal literal.
rodfersou commented 6 years ago

This is the way the validation works now:

ipdb> value
u'400,5540'
ipdb> self.type
<type 'float'>
ipdb> self.formatter.parse(value)
*** NumberParseError: Not a valid number for this pattern u'#,##0.###;-#,##0.###'.

The generated regex is wrong, float type can have 53 bits of precision instead of just 3.