mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Fixes form rendering when scheduling_enabled is disabled (#13123)
* fixes form rendering when scheduling_enabled is disabled #13096 * Remove requires_input property from BaseScript; render form consistently --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
bc7678c716
commit
cab7b76220
@ -56,10 +56,3 @@ class ScriptForm(BootstrapMixin, forms.Form):
|
|||||||
self.cleaned_data['_schedule_at'] = local_now()
|
self.cleaned_data['_schedule_at'] = local_now()
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
@property
|
|
||||||
def requires_input(self):
|
|
||||||
"""
|
|
||||||
A boolean indicating whether the form requires user input (ignore the built-in fields).
|
|
||||||
"""
|
|
||||||
return bool(len(self.fields) > 3)
|
|
||||||
|
@ -366,7 +366,7 @@ class BaseScript:
|
|||||||
if self.fieldsets:
|
if self.fieldsets:
|
||||||
fieldsets.extend(self.fieldsets)
|
fieldsets.extend(self.fieldsets)
|
||||||
else:
|
else:
|
||||||
fields = (name for name, _ in self._get_vars().items())
|
fields = list(name for name, _ in self._get_vars().items())
|
||||||
fieldsets.append(('Script Data', fields))
|
fieldsets.append(('Script Data', fields))
|
||||||
|
|
||||||
# Append the default fieldset if defined in the Meta class
|
# Append the default fieldset if defined in the Meta class
|
||||||
@ -390,6 +390,11 @@ class BaseScript:
|
|||||||
# Set initial "commit" checkbox state based on the script's Meta parameter
|
# Set initial "commit" checkbox state based on the script's Meta parameter
|
||||||
form.fields['_commit'].initial = self.commit_default
|
form.fields['_commit'].initial = self.commit_default
|
||||||
|
|
||||||
|
# Hide fields if scheduling has been disabled
|
||||||
|
if not self.scheduling_enabled:
|
||||||
|
form.fields['_schedule_at'].widget = forms.HiddenInput()
|
||||||
|
form.fields['_interval'].widget = forms.HiddenInput()
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
<form action="" method="post" enctype="multipart/form-data" class="form form-object-edit">
|
<form action="" method="post" enctype="multipart/form-data" class="form form-object-edit">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="field-group my-4">
|
<div class="field-group my-4">
|
||||||
{% if form.requires_input %}
|
{# Render grouped fields according to declared fieldsets #}
|
||||||
{# Render grouped fields according to declared fieldsets #}
|
{% for group, fields in script.get_fieldsets %}
|
||||||
{% for group, fields in script.get_fieldsets %}
|
{% if fields %}
|
||||||
<div class="field-group mb-5">
|
<div class="field-group mb-5">
|
||||||
<div class="row mb-2">
|
<div class="row mb-2">
|
||||||
<h5 class="offset-sm-3">{{ group }}</h5>
|
<h5 class="offset-sm-3">{{ group }}</h5>
|
||||||
@ -28,14 +28,8 @@
|
|||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
{% else %}
|
{% endfor %}
|
||||||
<div class="alert alert-info">
|
|
||||||
<i class="mdi mdi-information"></i>
|
|
||||||
This script does not require any input to run.
|
|
||||||
</div>
|
|
||||||
{% render_form form %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="float-end">
|
<div class="float-end">
|
||||||
<a href="{% url 'extras:script_list' %}" class="btn btn-outline-danger">Cancel</a>
|
<a href="{% url 'extras:script_list' %}" class="btn btn-outline-danger">Cancel</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user