The following piece of code demonstrates how to validate a form when user click on a normal button:
<form>
<button id="loginButton" type="button">Login</a>
</form>
<script>
document.addEventListener('DOMContentLoaded', function(e) {
const fv = FormValidation.formValidation(demoForm, {
fields: { ... },
plugins: { ... },
});
const loginButton = document.getElementById('loginButton');
loginButton.addEventListener('click', function() {
fv.validate().then(function(status) {
...
});
});
});
</script>
const loginButton = document.getElementById('loginButton');
const fv = FormValidation.formValidation(demoForm, {
fields: { ... },
plugins: { ... },
}).on('core.form.validating', function() {
loginButton.innerHTML = 'Validating ...';
});
loginButton.addEventListener('click', function() {
fv.validate().then(function(status) {
loginButton.innerHTML = (status === 'Valid')
? 'Form is validated. Logging in ...'
: 'Please try again';
});
});