Howdy,
Am slowly getting comfortable with the ACF JavaScript API. What I am doing is simple, I have an array of email addresses and if the user specifies an email address in a field that’s in that array, it displays a notice.
Works well, but even though the notice is shown, the user is allowed to post. I would like to mimic the behaviour that not entering a required field has: you can’t publish the post unless the error is fixed.
Other than disabling the publish button, I was wondering of there was a way to do this? My code just in case:
const emailField = acf.getField('field_sponsor_email_participant_email');
// Javascript Email Field
const emailInputField = document.querySelector('.participant-email input');
emailInputField.addEventListener( 'keyup', (e) => {
let newUserEmail = emailInputField.value;
if( emailList.includes(newUserEmail) ) {
emailField.showNotice({
text: 'The specified email already exists in the system',
type: 'error',
dismiss: false
});
} else {
emailField.removeNotice();
}
});
This may not help you but I would do this with an acf/validate_value filer.
@hube2 Actually, that works perfectly, thank you.