mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Fixes #1101: Fix AJAX scripting for device component selection forms
This commit is contained in:
parent
861c8b29c0
commit
1fa084b6be
@ -316,7 +316,7 @@ class IPAddressForm(BootstrapMixin, ReturnURLForm, CustomFieldForm):
|
|||||||
interface_rack = forms.ModelChoiceField(
|
interface_rack = forms.ModelChoiceField(
|
||||||
queryset=Rack.objects.all(), required=False, label='Rack', widget=APISelect(
|
queryset=Rack.objects.all(), required=False, label='Rack', widget=APISelect(
|
||||||
api_url='/api/dcim/racks/?site_id={{interface_site}}', display_field='display_name',
|
api_url='/api/dcim/racks/?site_id={{interface_site}}', display_field='display_name',
|
||||||
attrs={'filter-for': 'interface_device'}
|
attrs={'filter-for': 'interface_device', 'nullable': 'true'}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
interface_device = forms.ModelChoiceField(
|
interface_device = forms.ModelChoiceField(
|
||||||
|
@ -88,20 +88,21 @@ $(document).ready(function() {
|
|||||||
// Determine the filter fields needed to make an API call
|
// Determine the filter fields needed to make an API call
|
||||||
var filter_regex = /\{\{([a-z_]+)\}\}/g;
|
var filter_regex = /\{\{([a-z_]+)\}\}/g;
|
||||||
var match;
|
var match;
|
||||||
|
var rendered_url = api_url;
|
||||||
while (match = filter_regex.exec(api_url)) {
|
while (match = filter_regex.exec(api_url)) {
|
||||||
var filter_field = $('#id_' + match[1]);
|
var filter_field = $('#id_' + match[1]);
|
||||||
if (filter_field.val()) {
|
if (filter_field.val()) {
|
||||||
api_url = api_url.replace(match[0], filter_field.val());
|
rendered_url = rendered_url.replace(match[0], filter_field.val());
|
||||||
} else if ($(this).attr('nullable') == 'true') {
|
} else if (filter_field.attr('nullable') == 'true') {
|
||||||
api_url = api_url.replace(match[0], '0');
|
rendered_url = rendered_url.replace(match[0], '0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all URL variables have been replaced, make the API call
|
// If all URL variables have been replaced, make the API call
|
||||||
if (api_url.search('{{') < 0) {
|
if (rendered_url.search('{{') < 0) {
|
||||||
console.log(child_name + ": Fetching " + api_url);
|
console.log(child_name + ": Fetching " + rendered_url);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: api_url,
|
url: rendered_url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (response, status) {
|
success: function (response, status) {
|
||||||
$.each(response, function (index, choice) {
|
$.each(response, function (index, choice) {
|
||||||
|
Loading…
Reference in New Issue
Block a user