The following form collects the user's feedback. It would like to know the user's email address. However, the user can send the feedback anonymously.
const demoForm = document.getElementById('demoForm');
const fv = FormValidation.formValidation(demoForm, {
fields: {
email: {
validators: {
notEmpty: {
enabled: true,
message: 'The email address is required',
},
emailAddress: {
message: 'You must enter a valid email address',
},
},
},
},
});
These validators are enabled initially. However, they can be disabled or enabled based on the fact that the Submit anonymously option is chosen or not.
demoForm.querySelector('[name="submitAnonymously"]').addEventListener('change', function (e) {
e.target.checked ? fv.disableValidator('email') : fv.enableValidator('email');
fv.revalidateField('email');
});