MultipleHiddenInput
Handle < input type="hidden" > for fields that have a list of values.
Attributes
| Attribute | Type | Description |
|---|---|---|
| template_name | string = "django/forms/widgets/multiple_hidden.html" | The path to the HTML template used to render the multiple hidden input fields. |
Methods
get_context()
@classmethod
def get_context(
name: str,
value: list,
attrs: dict
) - > dict
Prepares the template context for rendering multiple hidden inputs, ensuring each sub-widget has a unique ID attribute if a base ID is provided.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The name of the form field to be used as the input name attribute. |
| value | list | A list of values to be rendered as individual hidden input elements. |
| attrs | dict | A dictionary of HTML attributes to be applied to the widget elements. |
Returns
| Type | Description |
|---|---|
dict | A dictionary containing the widget context, including a list of sub-widgets for each value in the multi-value field. |
value_from_datadict()
@classmethod
def value_from_datadict(
data: dict,
files: dict,
name: str
) - > list
Extracts the list of values for this widget from the submitted form data, supporting both multi-value query dicts and standard dictionaries.
Parameters
| Name | Type | Description |
|---|---|---|
| data | dict | The dictionary-like object containing submitted form data (e.g., request.POST). |
| files | dict | The dictionary-like object containing uploaded file data. |
| name | str | The name of the field to look up in the data dictionary. |
Returns
| Type | Description |
|---|---|
list | The list of values associated with the field name, or a single value if the data source does not support multiple values. |
format_value()
@classmethod
def format_value(
value: any
) - > list
Ensures the provided value is returned as a list, converting None to an empty list to facilitate iteration during rendering.
Parameters
| Name | Type | Description |
|---|---|---|
| value | any | The raw value to be formatted for use in the widget template. |
Returns
| Type | Description |
|---|---|
list | The original value if it is not None, otherwise an empty list. |