mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #9291: Improve data validation for MultiObjectVar script fields
This commit is contained in:
@ -135,11 +135,12 @@ class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultip
|
||||
widget = widgets.APISelectMultiple
|
||||
|
||||
def clean(self, value):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
value = value or []
|
||||
|
||||
# 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 [None, *value]
|
||||
|
||||
return super().clean(value)
|
||||
|
Reference in New Issue
Block a user