SOLVED

How can I have the form fields highlight in red (for errors from validation) ONLY after the user hits on the submit button?

Go to solution
Anonymous
Not applicable

How can I have the form fields highlight in red (for errors from validation) ONLY after the user hits on the submit button?

Currently, the form fields' are being highlighted in red from the mktoInvalid class that's being added, even before the user hits on "Submit", as soon as the field has been clicked on. Is there any way to have this validation check run only after the user hits on Submit? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How can I have the form fields highlight in red (for errors from validation) ONLY after the user hits on the submit button?

Yes, Min, you can do this.

Using CSS, hide the .mktoError and related styles by default.  Then, in a custom onValidate function, restore the visibility (an easy way is to add a class to the <FORM> that overrides the previous styles).  The onValidate does not run when entering or leaving the field, but only (by default) when the submit button is pressed.

View solution in original post

2 REPLIES 2
Frank_Breen2
Level 10

Re: How can I have the form fields highlight in red (for errors from validation) ONLY after the user hits on the submit button?

Marketo has validation rules turned on for some fields, for example Email should be a valid Email Address, clicking on and off the field will activate the error message, other field types have the same sort of features, see here - Custom Field Type Glossary - Marketo Docs - Product Docs

SanfordWhiteman
Level 10 - Community Moderator

Re: How can I have the form fields highlight in red (for errors from validation) ONLY after the user hits on the submit button?

Yes, Min, you can do this.

Using CSS, hide the .mktoError and related styles by default.  Then, in a custom onValidate function, restore the visibility (an easy way is to add a class to the <FORM> that overrides the previous styles).  The onValidate does not run when entering or leaving the field, but only (by default) when the submit button is pressed.