mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
Add errors to form, if they occur
This commit is contained in:
parent
96db5c1e75
commit
fb5d9cbf7d
@ -1,34 +1,39 @@
|
|||||||
function SubmitAddJobForm(newJobFormElement, progressModalElement, request) {
|
function SubmitAddJobForm(newJobFormElement, progressModalElement, request) {
|
||||||
var formData;
|
var formData = new FormData(newJobFormElement);
|
||||||
var progress;
|
var progressModal = M.Modal.getInstance(progressModalElement);
|
||||||
var progressModal;
|
|
||||||
|
|
||||||
formData = new FormData(newJobFormElement);
|
|
||||||
progressModal = M.Modal.getInstance(progressModalElement);
|
|
||||||
|
|
||||||
progressModal.options.dismissible = false;
|
progressModal.options.dismissible = false;
|
||||||
progressModalElement.querySelector(".title").innerHTML = newJobFormElement.title.value;
|
progressModalElement.querySelector(".title").innerHTML = newJobFormElement.title.value;
|
||||||
request.upload.addEventListener("progress", function(event) {
|
|
||||||
progressInPercent = Math.floor(100 * event.loaded / event.total).toString() + "%";
|
request.addEventListener("abort", function(event) {
|
||||||
progressModalElement.querySelector(".progress-in-percent").innerHTML = progressInPercent;
|
progressModalElement.querySelector(".progress-in-percent").innerHTML = "0%";
|
||||||
progressModalElement.querySelector(".determinate").style.width = progressInPercent;
|
progressModalElement.querySelector(".determinate").style.width = "0%";
|
||||||
});
|
});
|
||||||
request.addEventListener("load", function(event) {
|
request.addEventListener("load", function(event) {
|
||||||
if (request.status === 201) {
|
if (request.status === 201) {
|
||||||
window.location.href = JSON.parse(this.responseText)['redirect_url'];
|
window.location.href = JSON.parse(this.responseText)['redirect_url'];
|
||||||
}
|
}
|
||||||
if (request.status === 400) {
|
if (request.status === 400) {
|
||||||
console.log(JSON.parse(this.responseText));
|
progressModal.close();
|
||||||
// TODO print errors under input fields.
|
progressModalElement.querySelector(".progress-in-percent").innerHTML = "0%";
|
||||||
|
progressModalElement.querySelector(".determinate").style.width = "0%";
|
||||||
|
for (let [field, errors] of Object.entries(JSON.parse(this.responseText))) {
|
||||||
|
let fieldElement = document.getElementById(field).closest('.input-field');
|
||||||
|
for (let error of errors) {
|
||||||
|
fieldElement.insertAdjacentHTML('beforeend', '<span class="helper-text red-text">' + error + '</span>');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (request.status === 500) {
|
if (request.status === 500) {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
request.addEventListener("abort", function(event) {
|
request.upload.addEventListener("progress", function(event) {
|
||||||
progressModalElement.querySelector(".progress-in-percent").innerHTML = "0%";
|
progressInPercent = Math.floor(100 * event.loaded / event.total).toString() + "%";
|
||||||
progressModalElement.querySelector(".determinate").style.width = "0%";
|
progressModalElement.querySelector(".progress-in-percent").innerHTML = progressInPercent;
|
||||||
|
progressModalElement.querySelector(".determinate").style.width = progressInPercent;
|
||||||
});
|
});
|
||||||
|
|
||||||
progressModal.open();
|
progressModal.open();
|
||||||
request.open("POST", window.location.href);
|
request.open("POST", window.location.href);
|
||||||
request.send(formData);
|
request.send(formData);
|
||||||
|
Loading…
Reference in New Issue
Block a user