in ui/src/main/frontend/js/cms.form.js [36:105]
async function submitForm() {
let jcrcontent = false;
const { callback } = form.dataset;
const formData = new FormData(form);
form.querySelectorAll("input,select,textarea").forEach((el) => {
if (el.name.indexOf("jcr:content") !== -1) {
jcrcontent = true;
}
});
if (
form.dataset.addDate &&
!form.querySelector('input[name="jcr:content/jcr:lastModified"]')
) {
const dateContainer = document.createElement("div");
if (jcrcontent) {
dateContainer.innerHTML =
'<input type="hidden" name="jcr:content/jcr:lastModified" />' +
'<input type="hidden" name="jcr:content/jcr:lastModifiedBy" />' +
'<input type="hidden" name="jcr:content/jcr:created" />' +
'<input type="hidden" name="jcr:content/jcr:createdBy" />';
} else {
dateContainer.innerHTML =
'<input type="hidden" name="jcr:lastModified" />' +
'<input type="hidden" name="jcr:lastModifiedBy" />' +
'<input type="hidden" name="jcr:created" />' +
'<input type="hidden" name="jcr:createdBy" />';
}
form.appendChild(dateContainer);
}
const action = form.getAttribute("action");
const response = await fetch(action, {
method: "POST",
body: formData,
cache: "no-cache",
headers: {
Accept: "application/json",
},
});
if (Sling.CMS.utils.ok(response)) {
let res = {};
if (
response.headers.get("content-type").indexOf("application/json") !==
-1
) {
res = await response.json();
}
form.querySelector(".form-wrapper").disabled = false;
if (callback && Sling.CMS.handlers[callback]) {
Sling.CMS.handlers[callback](res, "success");
} else if (window.parent.window.CMSEditor) {
let reloadParent = false;
let { path } = res;
res.changes.forEach((change) => {
if (change.type !== "modified") {
reloadParent = true;
}
});
if (reloadParent) {
const pathArr = path.split("/");
pathArr.pop();
path = pathArr.join("/");
}
Sling.CMS.ui.confirmReloadComponent(res, "success", path);
} else {
Sling.CMS.ui.confirmReload(res, "success");
}
} else {
form.querySelector(".form-wrapper").disabled = false;
}
}