Last active
January 7, 2020 23:00
-
-
Save wwwisie/faef68540a1e0decf37acd5cd5e98dfe to your computer and use it in GitHub Desktop.
Example starter JavaScript for disabling form submissions if there are invalid fields
This file contains hidden or 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
| <button type="submit" id="submit-btn" class="btn btn-primary btn-block d-flex align-items-center justify-content-center"> | |
| <div class="text"> | |
| Solicitar cita | |
| </div> | |
| <div> | |
| <img src="/assets/ens/svg/checkmark.svg" alt=""> | |
| </div> | |
| </button> |
This file contains hidden or 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
| (function () { | |
| 'use strict'; | |
| window.addEventListener('load', function () { | |
| // Fetch all the forms we want to apply custom Bootstrap validation styles to | |
| var forms = document.getElementsByClassName('needs-validation'); | |
| // Loop over them and prevent submission | |
| var validation = Array.prototype.filter.call(forms, function (form) { | |
| form.addEventListener('submit', function (event) { | |
| if (form.checkValidity() === false) { | |
| event.preventDefault(); | |
| event.stopPropagation(); | |
| } | |
| else { | |
| $("#submit-btn .text").text("Enviado"); | |
| $("#submit-btn").addClass("active"); | |
| } | |
| form.classList.add('was-validated'); | |
| }, false); | |
| }); | |
| }, false); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment