Custom validation with custom error message and invalid field #1796
Replies: 1 comment 1 reply
-
So you can go about adding validation this way, or you could use the registerFormieValidation event, which is a little easier. Here you define your logic for validation, and the message to show in the field. I'd probably encourage this approach, and despite thing changing a little in Formie 3 for Craft 5, it's an organised way to register validators. Otherwise, to get the error to show up, you're a little bit on your own. Although using:
is what we use to show server-side errors in the client-side validator library. Just supply it with the Indeed, you can hook into the |
Beta Was this translation helpful? Give feedback.
-
I'm adding custom validation to a form, and while I have the basics pretty much down, I'm struggling to get the desired errors shown at the end.
When a user submits a form, I need to hit a controller action to check if the zip code is in the client's service area. If not, I want to trigger a form error. The form error alert should explain why the submission failed, so I want to include a custom message. I also want the form's zip code field to be marked as invalid and to show a field error.
In my own JS class, I started out with this:
However, the
formSubmitError()
shows the form's default error message. After digging in the source code, I found some relevant methods on the Form Theme class, so I modified my code:This got me closer to what I want, but I'm still not sure what to do to get the target field marked as invalid. Any help?
Beta Was this translation helpful? Give feedback.
All reactions