Commits

Anonymous committed 69f65f7

added filter when processing BooleanField instead of assuming that an empty field won't be submitted

Comments (0)

Files changed (1)

wtforms/fields/core.py

         self.data = bool(value)
 
     def process_formdata(self, valuelist):
-        # Checkboxes and submit buttons simply do not send a value when
-        # unchecked/not pressed. So the actual value="" doesn't matter for
-        # purpose of determining .data, only whether one exists or not.
-        self.data = bool(valuelist)
+        # Its not safe to assume that an unchecked field won't be submitted,
+        # when using via ajax (ie. Backbone model's .save) sometimes its
+        # better to include the falsy field. So be safe, we filter valuelist
+        # instead and check if we can find a truthy value and cast to bool
+        # from there.
+        self.data = bool(filter(lambda e: e, valuelist))
 
     def _value(self):
         if self.raw_data: