A clean way to attach error messages to form fields? #466
-
I created a haskell module that calculates I could make a form state type that looks like this.
I could fill in error fields in EventM. RenderM could render error messages below fields. Is there a cleaner way to attach error messages to form fields? |
Beta Was this translation helpful? Give feedback.
Answered by
jtdaugherty
May 14, 2023
Replies: 1 comment 8 replies
-
It seems I should just have one error field for showing the first error because presenting many errors at once will overwhelm people. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The built-in form is not designed to specifically allow for presenting validation errors when the per-field validators fail. Validation states are expressed using form attributes. If you want to display your own validation errors, I suspect you’ll need to subvert the built-in validation machinery and just store the validation errors as part of the field values themselves, which you can then have control over rendering. So, for example, instead of having a value of type
a
in your form state, have a value of typeEither ValidationError a
. That’ll require you to also update your form state inEventM
after you’ve run your own validators.