Commits

aidanskinner committed 60c627d

validators.DataRequired: allow 0, 0.0 as valid values

Int or Float fields should allow zero as a valid entry,
but not empty

Comments (0)

Files changed (2)

tests/validators.py

         self.assertEqual(len(f.errors), 1)
         self.assertRaises(StopValidation, required(), self.form, f)
         self.assertEqual(len(f.errors), 0)
+        f = DummyField(0)
+        required()(self.form, f)
+        self.assertEqual(len(f.errors), 0)
 
     def test_optional(self):
         self.assertEqual(optional()(self.form, DummyField('foobar', raw_data=['foobar'])), None)

wtforms/validators.py

         self.message = message
 
     def __call__(self, form, field):
-        if not field.data or isinstance(field.data, basestring) and not field.data.strip():
+        if field.data is None or isinstance(field.data, basestring) and not field.data.strip():
             if self.message is None:
                 self.message = field.gettext(u'This field is required.')