RadioSelect
This class provides a widget for rendering a group of radio buttons as a single selection form field. It utilizes specific HTML templates for the radio group and individual options, ensuring structured output through the use of a fieldset. The class also includes specialized logic for label identification to enhance accessibility for screen reader users.
Attributes
| Attribute | Type | Description |
|---|---|---|
| input_type | string = radio | The HTML input type attribute used for the widget, which is set to "radio". |
| template_name | string = django/forms/widgets/radio.html | The path to the Django HTML template used to render the radio group container. |
| option_template_name | string = django/forms/widgets/radio_option.html | The path to the Django HTML template used to render each individual radio option. |
| use_fieldset | boolean = true | A boolean flag indicating that the widget should be wrapped in a fieldset element for improved accessibility and grouping. |
Constructor
Signature
def RadioSelect()
Methods
id_for_label()
@classmethod
def id_for_label(
id_: string,
index: string = None
) - > string
Don't include for="field_0" in < label > to improve accessibility when using a screen reader, in addition clicking such a label would toggle the first input.
Parameters
| Name | Type | Description |
|---|---|---|
| id_ | string | The base ID of the widget field used to generate unique identifiers for sub-widgets. |
| index | string = None | The specific index of the radio option within the choice set used to suffix the base ID. |
Returns
| Type | Description |
|---|---|
string | The HTML ID attribute value for a specific radio option, or an empty string if no index is provided to prevent incorrect label association. |