[Zope-dev] Decimal validation error.

Hermann Himmelbauer dusty at qwer.tk
Thu Feb 11 06:21:24 EST 2010


Am Mittwoch 10 Februar 2010 17:27:09 schrieb Mats Nordgren:
> I have an interface with a decimal field.  It validates fine for 1,2 and 3
> fractions but if I enter a decimal with 4 fractions I get validation error
> "The entered value is not a valid decimal literal."
>
> I'm using the pypi release of bluebream and z3c.form 2.3.2.

I remember that one - quite cumbersome. Try something like this:

# You should use the following interface for your forms:
class IMyDecimal(IDecimal):
    """Specify custom decimal interface"""

# Now create a custom data converter
class MyDecimalDataConverter(BaseDecimalDataConverter):
    """Adapt decimal data converter"""
    adapts(IMyDecimal, IWidget)
    # The amount of '#' after the '.' outlines the no. of decimal places
    pattern = '#,##0.####'   

# And specify in overrides.zcml
  <adapter  factory="mymodule.MyDecimalDataConverter" />

This works for me.

Best Regards,
Hermann

-- 
hermann at qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7


More information about the Zope-Dev mailing list