Skip to main content

CheckboxSelectMultiple

This class provides a form widget that renders a multiple-choice selection as a list of HTML checkbox inputs. It extends the radio selection functionality to allow for multiple active selections while disabling standard browser-side required validation to ensure flexible data entry. The widget uses specific templates for rendering the group and individual checkbox options.

Attributes

AttributeTypeDescription
allow_multiple_selectedboolean = TrueBoolean flag indicating that the widget supports selecting more than one option simultaneously.
input_typestring = checkboxThe HTML input type attribute used when rendering the widget's selection elements.
template_namestring = django/forms/widgets/checkbox_select.htmlThe path to the Django HTML template used to render the outer structure of the checkbox group.
option_template_namestring = django/forms/widgets/checkbox_option.htmlThe path to the Django HTML template used to render each individual checkbox option within the group.

Methods


use_required_attribute()

@classmethod
def use_required_attribute(
initial: any
) - > boolean

Don't use the 'required' attribute because browser validation would require all checkboxes to be checked instead of at least one.

Parameters

NameTypeDescription
initialanyThe initial value of the field used to determine if the attribute is necessary

Returns

TypeDescription
booleanAlways returns False to prevent incorrect browser-side validation of multiple checkboxes

value_omitted_from_data()

@classmethod
def value_omitted_from_data(
data: dict,
files: dict,
name: string
) - > boolean

HTML checkboxes don't appear in POST data if not checked, so it's never known if the value is actually omitted.

Parameters

NameTypeDescription
datadictThe dictionary of submitted form data
filesdictThe dictionary of submitted file data
namestringThe name of the widget used to look up values in the data dictionaries

Returns

TypeDescription
booleanAlways returns False because an empty submission is a valid state for multiple checkboxes