From 1b696f58a5c7c6c03d80deb04f4046b9427e264d Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 3 Jan 2023 08:54:32 -0500 Subject: [PATCH] Tweak form validation logic --- netbox/dcim/forms/common.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/netbox/dcim/forms/common.py b/netbox/dcim/forms/common.py index 39459941c..a2243ce2d 100644 --- a/netbox/dcim/forms/common.py +++ b/netbox/dcim/forms/common.py @@ -54,23 +54,20 @@ class InterfaceCommonForm(forms.Form): class ModuleCommonForm(forms.Form): def clean(self): - cleaned_data = super().clean() + super().clean() - # Skip form validation if field validation already found errors. - if self.errors: - return cleaned_data - - replicate_components = cleaned_data.get("replicate_components") - adopt_components = cleaned_data.get("adopt_components") - device = cleaned_data.get('device') - module_type = cleaned_data.get('module_type') - module_bay = cleaned_data.get('module_bay') + replicate_components = self.cleaned_data.get('replicate_components') + adopt_components = self.cleaned_data.get('adopt_components') + device = self.cleaned_data.get('device') + module_type = self.cleaned_data.get('module_type') + module_bay = self.cleaned_data.get('module_bay') if adopt_components: self.instance._adopt_components = True - # Bail out if we are not installing a new module or if we are not replicating components - if self.instance.pk or not replicate_components: + # Bail out if we are not installing a new module or if we are not replicating components (or if + # validation has already failed) + if self.errors or self.instance.pk or not replicate_components: self.instance._disable_replication = True return