forked from MarseyWorld/MarseyWorld
dont undisable button until form is submitted successfully
parent
9080d084e5
commit
ecf9cd9538
|
@ -102,31 +102,6 @@ for (const element of TH) {
|
||||||
element.addEventListener('click', () => {sort_table(element)});
|
element.addEventListener('click', () => {sort_table(element)});
|
||||||
}
|
}
|
||||||
|
|
||||||
const btns_to_disable = document.querySelectorAll('[type="submit"]')
|
|
||||||
for (const element of btns_to_disable) {
|
|
||||||
if (!element.classList.contains("donotdisable"))
|
|
||||||
element.addEventListener('click', () => {disable_btn(element)})
|
|
||||||
}
|
|
||||||
|
|
||||||
function disable_btn(t) {
|
|
||||||
if (!t.classList.contains('disabled')) {
|
|
||||||
const isShopConfirm = t.id.startsWith('buy-') || t.id.startsWith('giveaward')
|
|
||||||
|
|
||||||
if (!isShopConfirm) {
|
|
||||||
t.classList.add('disabled');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
t.disabled = true;
|
|
||||||
}, 0.1);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
t.classList.remove("disabled");
|
|
||||||
t.disabled = false;
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function register_new_elements(e) {
|
function register_new_elements(e) {
|
||||||
const oninput = e.querySelectorAll('[data-oninput]');
|
const oninput = e.querySelectorAll('[data-oninput]');
|
||||||
for (const element of oninput) {
|
for (const element of oninput) {
|
||||||
|
|
|
@ -291,6 +291,10 @@ function prepare_to_pause(audio) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendFormXHR(form, extraActionsOnSuccess) {
|
function sendFormXHR(form, extraActionsOnSuccess) {
|
||||||
|
const submit_btn = form.querySelector('[type="submit"]')
|
||||||
|
submit_btn.disabled = true;
|
||||||
|
submit_btn.classList.add("disabled");
|
||||||
|
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
formData = new FormData(form);
|
formData = new FormData(form);
|
||||||
|
@ -318,6 +322,8 @@ function sendFormXHR(form, extraActionsOnSuccess) {
|
||||||
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
|
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
submit_btn.disabled = false;
|
||||||
|
submit_btn.classList.remove("disabled");
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
|
|
Loading…
Reference in New Issue