forked from rDrama/rDrama
keep "Post" button disabled
parent
c4394316fb
commit
104c6f1b89
|
@ -1,4 +1,5 @@
|
||||||
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
const IMAGE_FORMATS = document.getElementById('IMAGE_FORMATS').value.split(',')
|
||||||
|
const submitButton = document.getElementById('create_button')
|
||||||
|
|
||||||
document.getElementById('post-title').value = localStorage.getItem("post-title")
|
document.getElementById('post-title').value = localStorage.getItem("post-title")
|
||||||
document.getElementById('post-text').value = localStorage.getItem("post-text")
|
document.getElementById('post-text').value = localStorage.getItem("post-text")
|
||||||
|
@ -19,7 +20,6 @@ function checkForRequired() {
|
||||||
const title = document.getElementById("post-title");
|
const title = document.getElementById("post-title");
|
||||||
const url = document.getElementById("post-url");
|
const url = document.getElementById("post-url");
|
||||||
const text = document.getElementById("post-text");
|
const text = document.getElementById("post-text");
|
||||||
const button = document.getElementById("create_button");
|
|
||||||
const image = document.getElementById("file-upload");
|
const image = document.getElementById("file-upload");
|
||||||
const image2 = document.getElementById("file-upload-submit");
|
const image2 = document.getElementById("file-upload-submit");
|
||||||
|
|
||||||
|
@ -38,11 +38,11 @@ function checkForRequired() {
|
||||||
const isValidText = text.checkValidity();
|
const isValidText = text.checkValidity();
|
||||||
|
|
||||||
if (isValidTitle && (isValidURL || image.files.length > 0 || image2.files.length > 0)) {
|
if (isValidTitle && (isValidURL || image.files.length > 0 || image2.files.length > 0)) {
|
||||||
button.disabled = false;
|
submitButton.disabled = false;
|
||||||
} else if (isValidTitle && isValidText) {
|
} else if (isValidTitle && isValidText) {
|
||||||
button.disabled = false;
|
submitButton.disabled = false;
|
||||||
} else {
|
} else {
|
||||||
button.disabled = true;
|
submitButton.disabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkForRequired();
|
checkForRequired();
|
||||||
|
@ -205,8 +205,6 @@ document.addEventListener('keydown', (e) => {
|
||||||
if(!((e.ctrlKey || e.metaKey) && e.key === "Enter"))
|
if(!((e.ctrlKey || e.metaKey) && e.key === "Enter"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const submitButton = document.getElementById('create_button')
|
|
||||||
|
|
||||||
submitButton.click();
|
submitButton.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -231,6 +229,8 @@ function handleUploadProgress(evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function submit(form) {
|
function submit(form) {
|
||||||
|
submitButton.disabled = true;
|
||||||
|
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
formData = new FormData(form);
|
formData = new FormData(form);
|
||||||
|
@ -248,6 +248,7 @@ function submit(form) {
|
||||||
const post_id = JSON.parse(xhr.response)['post_id'];
|
const post_id = JSON.parse(xhr.response)['post_id'];
|
||||||
location.href = "/post/" + post_id
|
location.href = "/post/" + post_id
|
||||||
} else {
|
} else {
|
||||||
|
submitButton.disabled = false;
|
||||||
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
||||||
try {
|
try {
|
||||||
let data=JSON.parse(xhr.response);
|
let data=JSON.parse(xhr.response);
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
<progress id="file-progress" max="100"></progress>
|
<progress id="file-progress" max="100"></progress>
|
||||||
<span id="progress-percent"></span>
|
<span id="progress-percent"></span>
|
||||||
</span>
|
</span>
|
||||||
<button type="submit" class="btn btn-primary" id="create_button" type="submit" data-nonce="{{g.nonce}}" data-onclick="disable(this);remove_dialog()">Post</button>
|
<button type="submit" class="btn btn-primary" id="create_button" type="submit">Post</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue