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
| Attribute | Type | Description |
|---|---|---|
| allow_multiple_selected | boolean = True | A 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
| Name | Type | Description |
|---|---|---|
| data | dict | A dictionary-like object containing the submitted form data, typically request.POST or request.GET. |
| files | dict | A dictionary-like object containing uploaded file data. |
| name | string | The name of the form field used as the key to look up values in the data dictionary. |
Returns
| Type | Description |
|---|---|
list | A 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
| Name | Type | Description |
|---|---|---|
| data | dict | A dictionary-like object containing the submitted form data. |
| files | dict | A dictionary-like object containing uploaded file data. |
| name | string | The name of the form field to check for presence in the data. |
Returns
| Type | Description |
|---|---|
boolean | Always 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. |