trustpoint.formsยถ

Contains classes and helpers for forms that can be used in the whole project.

Classesยถ

DisableOptionsSelect

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.Select

A 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)

disabled_options = [][source]ยถ
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]