mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Return cleaned null_option
value as None
in dynamic multi-select field
This commit is contained in:
@ -485,5 +485,5 @@ class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultip
|
|||||||
"""
|
"""
|
||||||
if self.null_option is not None and settings.FILTERS_NULL_CHOICE_VALUE in value:
|
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]
|
value = [v for v in value if v != settings.FILTERS_NULL_CHOICE_VALUE]
|
||||||
return [self.null_option, *value]
|
return [None, *value]
|
||||||
return super().clean(value)
|
return super().clean(value)
|
||||||
|
@ -121,7 +121,6 @@ def get_selected_values(form, field_name):
|
|||||||
form.is_valid()
|
form.is_valid()
|
||||||
filter_data = form.cleaned_data.get(field_name)
|
filter_data = form.cleaned_data.get(field_name)
|
||||||
field = form.fields[field_name]
|
field = form.fields[field_name]
|
||||||
|
|
||||||
# Selection field
|
# Selection field
|
||||||
if hasattr(field, 'choices'):
|
if hasattr(field, 'choices'):
|
||||||
try:
|
try:
|
||||||
@ -130,12 +129,12 @@ def get_selected_values(form, field_name):
|
|||||||
if hasattr(field, 'null_option'):
|
if hasattr(field, 'null_option'):
|
||||||
# If the field has a `null_option` attribute set and it is selected,
|
# If the field has a `null_option` attribute set and it is selected,
|
||||||
# add it to the field's grouped choices.
|
# add it to the field's grouped choices.
|
||||||
if field.null_option is not None and field.null_option in filter_data:
|
if field.null_option is not None and None in filter_data:
|
||||||
grouped_choices.append((field.null_option, field.null_option))
|
grouped_choices.append((field.null_option, field.null_option))
|
||||||
|
|
||||||
choices = dict(unpack_grouped_choices(grouped_choices))
|
choices = dict(unpack_grouped_choices(grouped_choices))
|
||||||
return [
|
return [
|
||||||
label for value, label in choices.items() if str(value) in filter_data
|
label for value, label in choices.items() if str(value) in filter_data or None in filter_data
|
||||||
]
|
]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Field uses dynamic choices. Show all that have been populated.
|
# Field uses dynamic choices. Show all that have been populated.
|
||||||
|
Reference in New Issue
Block a user