mirror of
https://github.com/csd4ni3l/grass_touching_captcha.git
synced 2026-01-01 12:33:45 +01:00
fix an issue where you couldnt resubmit images after an error happened
This commit is contained in:
@@ -30,26 +30,27 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
file_input = document.getElementById("file_input");
|
function upload_success(image_url) {
|
||||||
file_input.addEventListener("change", function () {
|
|
||||||
|
|
||||||
var filereader = new FileReader();
|
|
||||||
|
|
||||||
function upload_success(image_url) {
|
|
||||||
document.getElementById("submit").disabled = false;
|
document.getElementById("submit").disabled = false;
|
||||||
document.getElementById("submit").innerHTML = "Submit"
|
document.getElementById("submit").innerHTML = "Submit"
|
||||||
|
|
||||||
document.getElementById("grass-touching-form").innerHTML += `<img class="preview-img" src="${image_url}"></img>`;
|
document.getElementById("grass-touching-form").innerHTML += `<img class="preview-img" src="${image_url}"></img>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload_error(error_message) {
|
function upload_error(error_message) {
|
||||||
console.error(error_message)
|
console.error(error_message)
|
||||||
|
|
||||||
file_input.value = ''
|
file_input.value = ''
|
||||||
|
|
||||||
document.getElementById("submit").innerHTML = "Submit"
|
document.getElementById("submit").innerHTML = "Submit"
|
||||||
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">${error_message}</div>`;
|
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">${error_message}</div>`;
|
||||||
}
|
|
||||||
|
|
||||||
function upload_file(file_type, file_content) {
|
file_input = document.getElementById("file_input");
|
||||||
|
file_input.removeEventListener("change", read_file);
|
||||||
|
file_input.addEventListener("change", read_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
function upload_file(file_type, file_content) {
|
||||||
fetch('{{ url_for("upload") }}', {
|
fetch('{{ url_for("upload") }}', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({image_data: file_content, image_type: file_type}),
|
body: JSON.stringify({image_data: file_content, image_type: file_type}),
|
||||||
@@ -83,7 +84,11 @@ file_input.addEventListener("change", function () {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read_file () {
|
||||||
|
file_input = document.getElementById("file_input");
|
||||||
|
var filereader = new FileReader();
|
||||||
|
|
||||||
filereader.onload = function () {
|
filereader.onload = function () {
|
||||||
document.getElementById("submit").innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span><span class="visually-hidden">Loading...</span>';
|
document.getElementById("submit").innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span><span class="visually-hidden">Loading...</span>';
|
||||||
@@ -102,7 +107,11 @@ file_input.addEventListener("change", function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
filereader.readAsDataURL(file_input.files[0]);
|
filereader.readAsDataURL(file_input.files[0]);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
file_input = document.getElementById("file_input");
|
||||||
|
file_input.addEventListener("change", read_file);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user