Description
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. Perhaps build
could return not only a JSX
, but a { trySubmit :: Effect (Maybe result), jsx :: JSX }
, where trySubmit
is defined as:
trySubmit = do
props.onChange setModified
pure (revalidate editor props props.value)
and then we might stop re-exporting revalidate
from Lumi.Components.Form
and make it only available from Form.Internal
, and also add a warning in the docs that you should probably be using trySubmit
instead.