-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to when validation messages are displayed #188
Comments
I guess this would probably also mean that we'd have to add a |
Since some of this is specific to
trySubmit = do
setModified
pure validated Ideally we would also automatically scroll back to the first invalid field or the last focused invalid field when form submission fails. Should we also consider browser |
It would make me very happy if it were possible to use all of our forms comfortably without a mouse. I do feel like submitting on |
At the moment, validation messages are displayed immediately, as soon as the form state for a validated form is modified:
Peek.2021-04-08.10-49.mp4
This is not ideal UX-wise - it feels a bit pushy of the form to start whining at you before you've even finished typing in the field. I think it would be preferable to wait until either the field loses focus or when the user attempts to submit the form to display these validation messages.
Another problem is that if I try to submit a form without filling in any required fields, validation errors are usually not shown. Again this is because we aren't setting validated form state fields to Modified when trying to submit the form, only when the form state for that field is changed.
These are separate issues but I think they might want tackling together; at least, we should probably ensure that trying to submit an invalid form cause any validation errors to be shown before we attempt to delay showing validation errors in form elements which have been modified until those elements lose focus, because in that case, if a "have I lost focus" flag doesn't get set properly for whatever reason then a validation error message might never appear at all.
Unfortunately there's probably no good non-breaking way of having attempted submission display validation errors - form submission is usually handled outside the form, via
revalidate
, which is pure and therefore doesn't provide the opportunity of modifying form state. Perhapsbuild
could return not only aJSX
, but a{ trySubmit :: Effect (Maybe result), jsx :: JSX }
, wheretrySubmit
is defined as:and then we might stop re-exporting
revalidate
fromLumi.Components.Form
and make it only available fromForm.Internal
, and also add a warning in the docs that you should probably be usingtrySubmit
instead.The text was updated successfully, but these errors were encountered: