Skip to content

Commit 35563d1

Browse files
committed
[fix:ui] Fixed relevant templates JS bug corner case
If the device has a template assigned to it with a backend which doesn't match the backend of the device, the code breaks, making it impossible for the admin to fix the issue using the web UI.
1 parent c9238fe commit 35563d1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

openwisp_controller/config/static/config/js/relevant_templates.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ django.jQuery(function ($) {
109109
// enabled templates on the top
110110
if (selectedTemplates !== undefined) {
111111
selectedTemplates.forEach(function (templateId, index) {
112+
// corner case in which backend of template does not match
113+
if (!data[templateId]) { return; }
112114
var element = getTemplateOptionElement(index, templateId, data[templateId], true, false),
113115
prefixElement = getTemplateOptionElement(index, templateId, data[templateId], true, true);
114116
sortedm2mUl.append(element);
@@ -123,6 +125,8 @@ django.jQuery(function ($) {
123125
// in the database.
124126
var counter = selectedTemplates !== undefined ? selectedTemplates.length : 0;
125127
Object.keys(data).forEach(function (templateId, index) {
128+
// corner case in which backend of template does not match
129+
if (!data[templateId]) { return; }
126130
index = index + counter;
127131
var isSelected = (data[templateId].default && (selectedTemplates === undefined)) && (!data[templateId].required),
128132
element = getTemplateOptionElement(index, templateId, data[templateId], isSelected),

0 commit comments

Comments
 (0)