Commits

Chris McDonough  committed c82d7db

- When the hidden widget is used to deserialize a field, return
``colander.null`` rather than the empty string so that it may be
used to represent non-text fields such as ``colander.Integer``.
This is isomorphic to the change done previously to
``deform.TextInputWidget`` to support nontextual empty fields.

  • Participants
  • Parent commits 14c9d7a

Comments (0)

Files changed (5)

 Changes
 =======
 
+Next Release
+------------
+
+Bug Fixes
+~~~~~~~~~
+
+- When the hidden widget is used to deserialize a field, return
+  ``colander.null`` rather than the empty string so that it may be
+  used to represent non-text fields such as ``colander.Integer``.
+  This is isomorphic to the change done previously to
+  ``deform.TextInputWidget`` to support nontextual empty fields.
+
 0.3
 ---
 

File deform/tests/test_widget.py

         result = widget.deserialize(field, null)
         self.assertEqual(result, null)
 
+    def test_deserialize_emptystring(self):
+        from colander import null
+        widget = self._makeOne(strip=False)
+        field = DummyField()
+        result = widget.deserialize(field, '')
+        self.assertEqual(result, null)
+
 class TestPasswordWidget(TestTextInputWidget):
     def _makeOne(self, **kw):
         from deform.widget import PasswordWidget

File deform/widget.py

         return field.renderer(self.template, field=field, cstruct=cstruct)
 
     def deserialize(self, field, pstruct):
-        if pstruct is null:
+        if not pstruct:
             return null
         return pstruct
 

File deformdemo/app.py

         form['sneaky'].widget = deform.widget.HiddenWidget()
         return self.render_form(form)
 
+    @bfg_view(renderer='templates/form.pt', name='hiddenmissing')
+    @demonstrate('Hidden, Missing Widget Representing an Integer')
+    def hiddenmissing(self):
+        class Schema(colander.Schema):
+            title = colander.SchemaNode(
+                colander.String())
+            number = colander.SchemaNode(
+                colander.Integer(),
+                missing=colander.null,
+                )
+        schema = Schema()
+        form = deform.Form(schema, buttons=('submit',))
+        form['number'].widget = deform.widget.HiddenWidget()
+        return self.render_form(form)
+
     @bfg_view(renderer='templates/form.pt', name='text_input_masks')
     @demonstrate('Text Input Masks')
     def text_input_masks(self):

File deformdemo/tests/test_demo.py

         self.assertEqual(browser.get_value('deformField1'), 'true')
         self.assertEqual(browser.get_text('css=#captured'), "{'sneaky': True}")
 
+class HiddenmissingTests(unittest.TestCase):
+    url = "/hiddenmissing/"
+    def test_render_default(self):
+        browser.open(self.url)
+        browser.wait_for_page_to_load("30000")
+        self.failIf(browser.is_element_present('css=.errorMsgLbl'))
+        self.assertEqual(browser.get_attribute('deformField1@name'), 'title')
+        self.assertEqual(browser.get_attribute('deformField2@name'), 'number')
+        self.assertEqual(browser.get_value('deformField1'), '')
+        self.assertEqual(browser.get_value('deformField2'), '')
+        self.assertEqual(browser.get_text('css=#captured'), 'None')
+    
+    def test_render_submitted(self):
+        browser.open(self.url)
+        browser.wait_for_page_to_load("30000")
+        browser.type('deformField1', 'yup')
+        browser.click('submit')
+        browser.wait_for_page_to_load("30000")
+        self.failIf(browser.is_element_present('css=.errorMsgLbl'))
+        self.assertEqual(browser.get_attribute('deformField1@name'), 'title')
+        self.assertEqual(browser.get_value('deformField1'), 'yup')
+        self.assertEqual(browser.get_text('css=#captured'),
+                         "{'number': <colander.null>, 'title': u'yup'}")
+
 class FileUploadTests(unittest.TestCase):
     url = "/file/"