refactor: extracts form submit button

template and js validation
This commit is contained in:
2024-11-21 13:00:11 -03:00
parent d3ff62299d
commit 5030eb42ce
4 changed files with 36 additions and 23 deletions

View File

@@ -27,4 +27,11 @@ body {
@media(min-width: 576px) {
margin-bottom: .5rem;
}
}
.submit-button {
width: 100%;
@media(min-width: 576px) {
width: 200px;
}
}

View File

@@ -0,0 +1,18 @@
(() => {
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
const forms = document.querySelectorAll('.needs-validation')
// Loop over them and prevent submission
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()