from django import forms from netbox.choices import ColorChoices from ..utils import add_blank_choice __all__ = ( 'BulkEditNullBooleanSelect', 'ClearableSelect', 'ColorSelect', 'HTMXSelect', 'SelectWithPK', 'SplitMultiSelectWidget', ) class BulkEditNullBooleanSelect(forms.NullBooleanSelect): """ A Select widget for NullBooleanFields """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Override the built-in choice labels self.choices = ( ('1', '---------'), ('2', 'Yes'), ('3', 'No'), ) class ClearableSelect(forms.Select): """ A Select widget that will be automatically cleared when one or more required fields are cleared. Args: requires_fields: A list of field names that this field depends on. When any of these fields are cleared, this field will also be cleared automatically via JavaScript. """ def __init__(self, *args, requires_fields=None, **kwargs): super().__init__(*args, **kwargs) if requires_fields: self.attrs['data-requires-fields'] = ','.join(requires_fields) class ColorSelect(forms.Select): """ Extends the built-in Select widget to colorize each