[Checkins] SVN: zc.extjs/branches/dev/src/zc/extjs/widgets. Added test for decimal widget.

Gintautas Miliauskas gintas at pov.lt
Thu Apr 3 17:44:40 EDT 2008


Log message for revision 85084:
  Added test for decimal widget.
  

Changed:
  U   zc.extjs/branches/dev/src/zc/extjs/widgets.py
  U   zc.extjs/branches/dev/src/zc/extjs/widgets.txt

-=-
Modified: zc.extjs/branches/dev/src/zc/extjs/widgets.py
===================================================================
--- zc.extjs/branches/dev/src/zc/extjs/widgets.py	2008-04-03 21:38:04 UTC (rev 85083)
+++ zc.extjs/branches/dev/src/zc/extjs/widgets.py	2008-04-03 21:44:39 UTC (rev 85084)
@@ -252,6 +252,12 @@
 
     widget_constructor = 'zc.extjs.widgets.InputDecimal'
 
+    def js_config(self):
+        result = Base.js_config(self)
+        if self.required:
+            result['allowBlank'] = False
+        return result
+
     def _is_missing(self, raw):
         return not raw
 

Modified: zc.extjs/branches/dev/src/zc/extjs/widgets.txt
===================================================================
--- zc.extjs/branches/dev/src/zc/extjs/widgets.txt	2008-04-03 21:38:04 UTC (rev 85083)
+++ zc.extjs/branches/dev/src/zc/extjs/widgets.txt	2008-04-03 21:44:39 UTC (rev 85084)
@@ -589,7 +589,50 @@
     >>> w.getInputValue()
     u'C'
 
+Decimals
+--------
 
+    >>> request = zope.publisher.browser.TestRequest()
+    >>> f = zope.schema.Decimal(
+    ...    __name__='f', title=u'label', description=u'hint')
+    >>> w = zc.extjs.widgets.InputDecimal(f, request)
+    >>> pprint(w.js_config(), width=1)
+    {'allowBlank': False,
+     'fieldHint': u'hint',
+     'fieldLabel': u'label',
+     'id': 'field.f',
+     'itemCls': 'zc-required-field',
+     'name': 'field.f',
+     'widget_constructor': 'zc.extjs.widgets.InputDecimal'}
+
+Note that we use a custom widget constructor, which provides
+decimal-specific validation on the client.
+
+    >>> import decimal
+    >>> w.formValue(None), w.formValue(decimal.Decimal("42.1"))
+    (None, u'42.1')
+
+    >>> w.required, w.hasInput(), w.hasValidInput()
+    (True, False, False)
+    >>> w.getInputValue()
+    Traceback (most recent call last):
+    ...
+    MissingInputError: ('field.f', u'label', None)
+
+    >>> request.form['field.f'] = u'xxx'
+    >>> w.required, w.hasInput(), w.hasValidInput()
+    (True, True, False)
+    >>> w.getInputValue()
+    Traceback (most recent call last):
+    ...
+    ConversionError: (u"Invalid decimal: u'xxx'", None)
+
+    >>> request.form['field.f'] = u'33.1'
+    >>> w.required, w.hasInput(), w.hasValidInput()
+    (True, True, True)
+    >>> w.getInputValue()
+    Decimal("33.1")
+
 Hidden fields
 -------------
 



More information about the Checkins mailing list