Skip to content

Commit 22590a4

Browse files
committed
[fix] Workaround for config UI when using variables in addresses
1 parent b05c875 commit 22590a4

File tree

1 file changed

+23
-0
lines changed
  • openwisp_controller/config/static/config/js

1 file changed

+23
-0
lines changed

openwisp_controller/config/static/config/js/widget.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
$.extend(options, JSON.parse(field.attr("data-options")));
236236
}
237237

238+
ipAddrMaxLengthWorkaround(startval, options.schema);
238239
editor = new JSONEditor(document.getElementById(id), options);
239240
django._jsonEditors[id] = editor;
240241
// initialise advanced json editor here (disable schema validation in VPN admin)
@@ -258,6 +259,7 @@
258259
// update raw value on change event
259260
editor.on('change', updateRaw);
260261
editor.on('change', handleMaxLengthAttr);
262+
261263
// update raw value before form submit
262264
form.submit(function (e) {
263265
// only submit form if the editor is clear of all validation errors
@@ -429,6 +431,27 @@
429431
getDefaultValues();
430432
});
431433
});
434+
435+
// deletes maxLength on ip address schema if address contains variable
436+
// this workaround is necessary until we rewrite the config UI to
437+
// deal with variables properly
438+
var ipAddrMaxLengthWorkaround = function(value, schema) {
439+
if (value && value.interfaces) {
440+
$.each(value.interfaces, function(i, interf) {
441+
if (interf.addresses) {
442+
$.each(interf.addresses, function(i, ip) {
443+
if (ip.address && ip.address.indexOf('{{') > -1) {
444+
var ipFamily = ip.family + '_address';
445+
try {
446+
delete schema.definitions[ipFamily].allOf[2].properties.address.maxLength;
447+
} catch (e) {}
448+
}
449+
});
450+
}
451+
});
452+
}
453+
};
454+
432455
// Export loadUi
433456
django._loadJsonSchemaUi = loadUi;
434457
}(django.jQuery));

0 commit comments

Comments
 (0)