Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/customization/custom-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ A particular object within NetBox. Each ObjectVar must specify a particular mode
* `query_params` - A dictionary of query parameters to use when retrieving available options (optional)
* `context` - A custom dictionary mapping template context variables to fields, used when rendering `<option>` elements within the dropdown menu (optional; see below)
* `null_option` - A label representing a "null" or empty choice (optional)
* `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)

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:

Expand Down
5 changes: 4 additions & 1 deletion netbox/extras/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,20 @@ class ObjectVar(ScriptVariable):
:param context: A custom dictionary mapping template context variables to fields, used when rendering <option>
elements within the dropdown menu (optional)
:param null_option: The label to use as a "null" selection option (optional)
:param selector: Include an advanced object selection widget to assist the user in identifying the desired
object (optional)
"""
form_field = DynamicModelChoiceField

def __init__(self, model, query_params=None, context=None, null_option=None, *args, **kwargs):
def __init__(self, model, query_params=None, context=None, null_option=None, selector=False, *args, **kwargs):
super().__init__(*args, **kwargs)

self.field_attrs.update({
'queryset': model.objects.all(),
'query_params': query_params,
'context': context,
'null_option': null_option,
'selector': selector,
})


Expand Down
4 changes: 4 additions & 0 deletions netbox/templates/extras/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ <h2 class="col-9 offset-3">{{ group }}</h2>
</div>
</div>
{% endblock content %}

{% block modals %}
{% include 'inc/htmx_modal.html' with size='lg' %}
{% endblock %}