Skip to main content

MultipleHiddenInput

Handle < input type="hidden" > for fields that have a list of values.

Attributes

AttributeTypeDescription
template_namestring = "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

NameTypeDescription
namestrThe name of the form field to be used as the input name attribute.
valuelistA list of values to be rendered as individual hidden input elements.
attrsdictA dictionary of HTML attributes to be applied to the widget elements.

Returns

TypeDescription
dictA 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

NameTypeDescription
datadictThe dictionary-like object containing submitted form data (e.g., request.POST).
filesdictThe dictionary-like object containing uploaded file data.
namestrThe name of the field to look up in the data dictionary.

Returns

TypeDescription
listThe 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

NameTypeDescription
valueanyThe raw value to be formatted for use in the widget template.

Returns

TypeDescription
listThe original value if it is not None, otherwise an empty list.