|
235 | 235 | $.extend(options, JSON.parse(field.attr("data-options"))); |
236 | 236 | } |
237 | 237 |
|
| 238 | + ipAddrMaxLengthWorkaround(startval, options.schema); |
238 | 239 | editor = new JSONEditor(document.getElementById(id), options); |
239 | 240 | django._jsonEditors[id] = editor; |
240 | 241 | // initialise advanced json editor here (disable schema validation in VPN admin) |
|
258 | 259 | // update raw value on change event |
259 | 260 | editor.on('change', updateRaw); |
260 | 261 | editor.on('change', handleMaxLengthAttr); |
| 262 | + |
261 | 263 | // update raw value before form submit |
262 | 264 | form.submit(function (e) { |
263 | 265 | // only submit form if the editor is clear of all validation errors |
|
429 | 431 | getDefaultValues(); |
430 | 432 | }); |
431 | 433 | }); |
| 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 | + |
432 | 455 | // Export loadUi |
433 | 456 | django._loadJsonSchemaUi = loadUi; |
434 | 457 | }(django.jQuery)); |
|
0 commit comments