-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spinner and disable submit button functionality on form submission
- Loading branch information
Prasham Marfatia
committed
Sep 27, 2024
1 parent
ed9da42
commit 0877daa
Showing
1 changed file
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
{% extends "base.html" %} | ||
|
||
{% import "bootstrap4/form.html" as wtf %} | ||
|
||
{% block container %} | ||
<div class="card card-body bg-light"> | ||
<h1 class="display-4">{% block header %}{% endblock %}</h1> | ||
<p class="lead"> | ||
{% block lead %}{% endblock %} | ||
</p> | ||
{{ wtf.render_form(form) }} | ||
<form id="main-form" method="POST"> | ||
{{ wtf.render_form(form) }} | ||
</form> | ||
</div> | ||
{% endblock %} | ||
{% block scripts %} | ||
{{ super() }} | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
let submitButton = document.getElementById('submit-btn'); | ||
let child = document.createElement("span") | ||
child.classList.add("spinner-border", "spinner-border-sm", "ml-2", "d-none") | ||
child.setAttribute("aria-hidden", "true") | ||
child.setAttribute("role", "status") | ||
child.id = "form-spinner" | ||
submitButton.parentElement.appendChild(child) | ||
|
||
const form = document.getElementById('main-form'); | ||
var spinner; | ||
|
||
form.addEventListener('submit', function(event) { | ||
submitButton.disabled = true; | ||
spinner = document.getElementById('form-spinner'); | ||
spinner.classList.remove("d-none") | ||
}); | ||
}); | ||
</script> | ||
{% endblock %} |