From e0d538ad310265a97b5f89c980d522cdd174ef2a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 29 Jan 2020 09:40:17 -0500 Subject: [PATCH] Fixes #4043: Fix toggling of required fields in custom scripts --- docs/release-notes/version-2.7.md | 8 ++++++++ netbox/extras/scripts.py | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index a6a6b65cfd6..ab1e2de0d1c 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -1,3 +1,11 @@ +# v2.7.4 (FUTURE) + +## Bug Fixes + +* [#4043](https://github.com/netbox-community/netbox/issues/4043) - Fix toggling of required fields in custom scripts + +--- + # v2.7.3 (2020-01-28) ## Enhancements diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index bd7e864e1d8..6567fe7078d 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -53,14 +53,15 @@ def __init__(self, label='', description='', default=None, required=True): # Initialize field attributes if not hasattr(self, 'field_attrs'): self.field_attrs = {} - if description: - self.field_attrs['help_text'] = description if label: self.field_attrs['label'] = label + if description: + self.field_attrs['help_text'] = description if default: self.field_attrs['initial'] = default - if required: - self.field_attrs['required'] = True + self.field_attrs['required'] = required + + # Initialize the list of optional validators if none have already been defined if 'validators' not in self.field_attrs: self.field_attrs['validators'] = []