Re: Decimal validation error.

Hermann Himmelbauer <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
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

-- 
[email protected]
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.