mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
#7205: Handle null_option
in dynamic multi-select choices field
This commit is contained in:
parent
a79f9566e9
commit
9f4b9b3476
@ -477,3 +477,13 @@ class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultip
|
|||||||
"""
|
"""
|
||||||
filter = django_filters.ModelMultipleChoiceFilter
|
filter = django_filters.ModelMultipleChoiceFilter
|
||||||
widget = widgets.APISelectMultiple
|
widget = widgets.APISelectMultiple
|
||||||
|
|
||||||
|
def clean(self, value: list[str]):
|
||||||
|
"""
|
||||||
|
When null option is enabled and "None" is sent as part of a form to be submitted, it is sent as the
|
||||||
|
string 'null'. This will check for that condition and gracefully handle the conversion to a NoneType.
|
||||||
|
"""
|
||||||
|
if self.null_option is not None and settings.FILTERS_NULL_CHOICE_VALUE in value:
|
||||||
|
value = [v for v in value if v != settings.FILTERS_NULL_CHOICE_VALUE]
|
||||||
|
return [self.null_option, *value]
|
||||||
|
return super().clean(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user