Commit 7e67e940 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_parameter_editor: Prevent submit form if form is invalid

   This implements checkValidity properly.
parent 78f68708
...@@ -514,7 +514,7 @@ ...@@ -514,7 +514,7 @@
software_type_list = options.software_type_list; software_type_list = options.software_type_list;
} }
if (options.softwaretype == "" || options.softwaretype === null) { if (options.softwaretype === "" || options.softwaretype === null) {
// Drop emtpy value for consistency // Drop emtpy value for consistency
delete options.softwaretype; delete options.softwaretype;
} }
...@@ -642,7 +642,35 @@ ...@@ -642,7 +642,35 @@
content_dict.text_content = xml_result; content_dict.text_content = xml_result;
return content_dict; return content_dict;
}); });
}, {mutex: 'statechange'}); }, {mutex: 'statechange'})
.declareMethod('checkValidity', function () {
var g = this;
return g.getElement()
.push(function (element) {
var text_content = element.querySelector('textarea[name=text_content]'),
doc;
if (!g.state.editable) {
// Anything not editable is valid.
return true;
}
if (text_content !== null) {
if (text_content.value === "") {
// This would use standard value from getContent (which is valid).
return true;
}
doc = new DOMParser().parseFromString(text_content.value, "text/xml");
if (doc.querySelector('parsererror') !== null) {
return false;
}
return true;
}
return g.getDeclaredGadget('json_form')
.push(function (gadget) {
return gadget.checkValidity();
});
});
});
}(window, rJS, XMLSerializer, DOMParser, vkbeautify, }(window, rJS, XMLSerializer, DOMParser, vkbeautify,
domsugar, Boolean, URI)); domsugar, Boolean, URI));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment