The following example will disable the
Submit button as long as there is at least one invalid field. In case all of fields are valid, the button will be enabled.
We can archive it by using the
onStatusChanged
option provided by the
FieldStatus plugin.
document.addEventListener('DOMContentLoaded', function(e) {
const demoForm = document.getElementById('demoForm');
const submitButton = demoForm.querySelector('[type="submit"]');
FormValidation.formValidation(
demoForm,
{
fields: {
...
},
plugins: {
fieldStatus: new FormValidation.plugins.FieldStatus({
onStatusChanged: function(areFieldsValid) {
areFieldsValid
? submitButton.removeAttribute('disabled')
: submitButton.setAttribute('disabled', 'disabled');
}
}),
...
},
}
);
});