Hi,
your suggestion was precious, I did small modifications in bold:
onFormReady: function($form) {
window.addEventListener(‘message’, event => {
if (event.data.type === ‘hsFormCallback’ && event.data.eventName === ‘onFormReady’) {
const input =$form.find(‘input[name=“firstname”]’);// document.querySelector(‘input[name=“firstname”]’) // Change this to the property you want to validate
// Error message
const error = document.createElement(‘div’)
error.setAttribute(‘class’, ‘form-error-message’)
error.innerHTML=‘error’;
input[0].addEventListener(‘input’, e => {
if (e.currentTarget.value.length > 5) {
// Time to display an error
input[0].parentElement.appendChild(error)
}
})
}
});
the last issue I have is where to put preventDefault(), please look at bold comment:
onFormReady: function($form) {
window.addEventListener(‘message’, event => {
event.preventDefault(); --> the form is still submitted
return false;
});
Thank You very much for your support