Skip to main content

SelectMultiple

This class represents a multiple-selection form widget that allows users to select one or more options from a list. It extends the standard selection functionality by enabling multiple selections and providing specialized logic to retrieve a list of values from submitted data. The class also ensures that the field is not considered omitted from data submissions, even when no options are selected.

Attributes

AttributeTypeDescription
allow_multiple_selectedboolean = TrueA boolean flag that enables the selection of multiple options within the HTML select widget.

Methods


value_from_datadict()

@classmethod
def value_from_datadict(
data: dict,
files: dict,
name: string
) - > list

Extracts the list of selected values for this widget from the provided data dictionary.

Parameters

NameTypeDescription
datadictA dictionary-like object containing the submitted form data, typically request.POST or request.GET.
filesdictA dictionary-like object containing uploaded file data.
namestringThe name of the form field used as the key to look up values in the data dictionary.

Returns

TypeDescription
listA list of selected values associated with the widget name, or None if the name is not present.

value_omitted_from_data()

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

Determines if the value for this widget is missing from the submitted data.

Parameters

NameTypeDescription
datadictA dictionary-like object containing the submitted form data.
filesdictA dictionary-like object containing uploaded file data.
namestringThe name of the form field to check for presence in the data.

Returns

TypeDescription
booleanAlways returns False because an unselected multiple select element does not appear in POST data, making it impossible to distinguish between an empty selection and an omitted field.