Skip to content

Commit 9cf098a

Browse files
committed
When using multiple checkboxes with the field marked as "required", don't pass the "required" attribute through to the widget as it means that all the checkboxes will need to be checked to validate.
I'd say that it's rarely the case you're really expecting the user to check every one; more that you expect them to check one or more. I think you'd have to distinguish these two use cases in the drop-down menu for the field type, but in the meantime, I propose that the default be the "at least one" scenario. The side effect of this that it can't be enforced in the client-side HTML5 without using Javascript.
1 parent dc19e85 commit 9cf098a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

forms_builder/forms/forms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ def __init__(self, form, context, *args, **kwargs):
202202

203203
# Add identifying CSS classes to the field.
204204
css_class = field_class.__name__.lower()
205-
if field.required:
205+
# Do not add the 'required' field to the CheckboxSelectMultiple because it will
206+
# mean that all checkboxes have to be checked instead of the usual use case of
207+
# "at least one".
208+
if field.required and (field_widget != forms.CheckboxSelectMultiple):
206209
css_class += " required"
207210
if settings.USE_HTML5:
208211
# Except Django version 1.10 this is necessary for all versions from 1.8 to 1.11.

0 commit comments

Comments
 (0)