Cannot set a custom error message

I am trying to set a custom error message on a form but so far unsuccessful.

I have created a HubSpot form, set as raw HTML, embedded it on page (using hbspt.forms.create()), and added custom field validators in JavaScript that are correctly being registered with a callback function and triggered. All this works.

When a specific validation is false, how do I set a custom error message?

The method setCustomValidity(“error message”) does not seem to work, nor does ‘textContent’.

Hi @birdman, hope you are doing well!

I have found this thread with several options you can try to accomplish your goal.

Hope this helps,

Diana

Hi @EDia - I have seen the article before but contains dead links. Do you know the solution? Best Martin

Hi Martin, thanks for letting me know, however when I go there the first link is this one, and works fine. Could you double-check? This will be the option available at the moment.

About the second one and third one that are the same one, you are right, those are no longer in the Marketplace for that reason you see a broken page.

Hope this helps clarify.

Best,

Diana

Hello Diane, the first link is all known to me and does not provide a solution to the challenge I am having. Thx anyway

When looking at the form customization code (see https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options), I see the option to change error messages. But how does this work for custom validations?

For example, I have a text input field, and there are 4 different validations it needs to pass. The error message that needs to be displayed is dependent on the specific validation.

I have created a project on GitHub that shows how to create custom form field validations using JavaScript (without jQuery) for those interested. See GitHub - birdmeister/hubspot-form-validation: Example of how to validate HubSpot form fields with JavaScript · GitHub
Any remarks, corrections and additions are more then welcome.

Hi @birdman :blush:

¡Fantastic! Thanks for sharing :blush:

Best,

Diana