diff --git a/src/components/AddExpenseForm.js b/src/components/AddExpenseForm.js index ba3241b..cbaa802 100644 --- a/src/components/AddExpenseForm.js +++ b/src/components/AddExpenseForm.js @@ -123,76 +123,98 @@ const AddExpenseForm = (props) => { setCost(event.target.value) } + (() => { + // 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) + }) + })() + return (