trustpoint.formsΒΆ
Contains classes and helpers for forms that can be used in the whole project.
ClassesΒΆ
A custom Select widget that allows disabling specific optionsm in a Django ChoiceField dropdown. |
Module ContentsΒΆ
- class trustpoint.forms.DisableOptionsSelect(attrs=None, disabled_options=None)[source]ΒΆ
Bases:
django.forms.SelectA custom Select widget that allows disabling specific optionsm in a Django ChoiceField dropdown.
- Example usage:
- forms.ChoiceField(
choices=β¦, widget=DisableOptionsSelect(disabled_options=[βsome_valueβ])
)
- Parameters:
attrs (dict[str, Any] | None)
disabled_options (list[Any] | None)
- create_option(name, value, label, selected, index, subindex=None, attrs=None)[source]ΒΆ
Create a single option dictionary for rendering.
Overrides the default method to add the disabled attribute for options whose value is in self.disabled_options.
- Parameters:
name (str) β Name of the form field.
value (Any) β Value of the option.
label (int | str) β Display label for the option.
selected (bool) β Whether the option is selected.
index (int) β Index of the option.
subindex (int | None) β Optional subindex for optgroups.
attrs (dict[str, Any] | None) β Additional HTML attributes.
- Returns:
A dictionary representing the option to render.
- Return type:
dict[str, Any]