mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Clean up Select2 widget Javascript
This commit is contained in:
@ -1688,7 +1688,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
api_url='/api/dcim/racks/{{rack}}/elevation/',
|
||||
attrs={
|
||||
'disabled-indicator': 'device',
|
||||
'data-additional-query-param-face': "[\"$face\"]",
|
||||
'data-query-param-face': "[\"$face\"]",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
@ -157,31 +157,10 @@ $(document).ready(function() {
|
||||
// Allow for controlling the brief setting from within APISelect
|
||||
parameters.brief = ( $(element).is('[data-full]') ? undefined : true );
|
||||
|
||||
// filter-for fields from a chain
|
||||
var attr_name = "data-filter-for-" + $(element).attr("name");
|
||||
var form = $(element).closest('form');
|
||||
var filter_for_elements = form.find("select[" + attr_name + "]");
|
||||
|
||||
filter_for_elements.each(function(index, filter_for_element) {
|
||||
var param_name = $(filter_for_element).attr(attr_name);
|
||||
var is_required = $(filter_for_element).attr("required");
|
||||
var is_nullable = $(filter_for_element).attr("data-null-option");
|
||||
var is_visible = $(filter_for_element).is(":visible");
|
||||
var value = $(filter_for_element).val();
|
||||
|
||||
if (param_name && is_visible) {
|
||||
if (value) {
|
||||
parameters[param_name] = value;
|
||||
} else if (is_required && is_nullable) {
|
||||
parameters[param_name] = "null";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Additional query params
|
||||
// Attach any extra query parameters
|
||||
$.each(element.attributes, function(index, attr){
|
||||
if (attr.name.includes("data-additional-query-param-")){
|
||||
var param_name = attr.name.split("data-additional-query-param-")[1];
|
||||
if (attr.name.includes("data-query-param-")){
|
||||
var param_name = attr.name.split("data-query-param-")[1];
|
||||
|
||||
$.each($.parseJSON(attr.value), function(index, value) {
|
||||
// Referencing the value of another form field
|
||||
|
@ -141,7 +141,7 @@ class APISelect(SelectWithDisabled):
|
||||
:param name: The name of the query param
|
||||
:param value: The value of the query param
|
||||
"""
|
||||
key = f'data-additional-query-param-{name}'
|
||||
key = f'data-query-param-{name}'
|
||||
|
||||
values = json.loads(self.attrs.get(key, '[]'))
|
||||
if type(value) is list:
|
||||
|
Reference in New Issue
Block a user