Skip to content

Commit 3e1d436

Browse files
authored
Closes #17944: Allow filtering of ObjectVar and MultiObjectVar script inputs (#18725)
* Add the advanced object selector to the ObjectVar and MultiObjectVar script inputs * Fix formatting issue
1 parent 3b1daaa commit 3e1d436

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

docs/customization/custom-scripts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ A particular object within NetBox. Each ObjectVar must specify a particular mode
308308
* `query_params` - A dictionary of query parameters to use when retrieving available options (optional)
309309
* `context` - A custom dictionary mapping template context variables to fields, used when rendering `<option>` elements within the dropdown menu (optional; see below)
310310
* `null_option` - A label representing a "null" or empty choice (optional)
311+
* `selector` - A boolean that, when True, includes an advanced object selection widget to assist the user in identifying the desired object (optional; False by default)
311312

312313
To limit the selections available within the list, additional query parameters can be passed as the `query_params` dictionary. For example, to show only devices with an "active" status:
313314

netbox/extras/scripts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,20 @@ class ObjectVar(ScriptVariable):
211211
:param context: A custom dictionary mapping template context variables to fields, used when rendering <option>
212212
elements within the dropdown menu (optional)
213213
:param null_option: The label to use as a "null" selection option (optional)
214+
:param selector: Include an advanced object selection widget to assist the user in identifying the desired
215+
object (optional)
214216
"""
215217
form_field = DynamicModelChoiceField
216218

217-
def __init__(self, model, query_params=None, context=None, null_option=None, *args, **kwargs):
219+
def __init__(self, model, query_params=None, context=None, null_option=None, selector=False, *args, **kwargs):
218220
super().__init__(*args, **kwargs)
219221

220222
self.field_attrs.update({
221223
'queryset': model.objects.all(),
222224
'query_params': query_params,
223225
'context': context,
224226
'null_option': null_option,
227+
'selector': selector,
225228
})
226229

227230

netbox/templates/extras/script.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ <h2 class="col-9 offset-3">{{ group }}</h2>
5454
</div>
5555
</div>
5656
{% endblock content %}
57+
58+
{% block modals %}
59+
{% include 'inc/htmx_modal.html' with size='lg' %}
60+
{% endblock %}

0 commit comments

Comments
 (0)