I have added a spinner to my form "Continue" button, but the button is clickable when the form is not filled out AT ALL, the button should not be able to spin and currently form will not SUBMIT anyway because required="" is in the input
const btn = document.querySelector(".button");
btn.classList.add("button--loading");
btn.classList.remove("button--loading");
.button {
position: relative;
padding: 8px 16px;
background: #009579;
border: none;
outline: none;
border-radius: 2px;
cursor: pointer;
}
.button:active {
background: #007a63;
}
.button__text {
font: bold 20px "Quicksand", san-serif;
color: #ffffff;
transition: all 0.2s;
}
.button--loading .button__text {
visibility: hidden;
opacity: 0;
}
.button--loading::after {
content: "";
position: absolute;
width: 16px;
height: 16px;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border: 4px solid transparent;
border-top-color: #ffffff;
border-radius: 50%;
animation: button-loading-spinner 1s ease infinite;
}
@keyframes button-loading-spinner {
from {
transform: rotate(0turn);
}
to {
transform: rotate(1turn);
}
}
<h1>Login</h1>
<input type="text" id="usr" name="usr" class="input input--text input-type__input input--w-6" maxlength="35" minlength="4" placeholder="e.g. name@example.com" autocomplete="email" required="">
<br>
<input type="password" id="password" name="password" class="input input--text input-type__input input--w-6" maxlength="35" minlength="2" placeholder="Password" autocomplete="current-password" required="">
<div class="orderweb__3a7c2968">
<div class="orderweb__f659f0f0"></div>
</div>
</div>
<br>
<div class="orderweb__d28fa935">
</span>
</div>
</div> <span class="ccl-67e0c7f3fe50cf69 ccl-a97a150ddadaa172">
<button type="submit" tabindex="0" onclick="this.classList.toggle('button--loading')" onclick="this.parentNode.style.display = 'none'" class="button ccl-d0484b0360a2b432 ccl-233931c277401e86 ccl-ed9aadeaa18a9f19 ccl-a97a150ddadaa172 btn u-mb-xl btn--loader js-loader js-submit-btn" name="action[save_continue]">
<span class="ccl-cce251427bbe4ec4">
<span class="btn__inner" onclick="this.parentNode.style.display = 'none'">Continue</span> </button>