Is there a good pattern to render server-side input validation errors on Forms v5 input fields and mount input error classes with human-readable error messages for errors that cannot be known by client before submitting?
Ideally the form state that is passed down to Input! should have some errors that came from server, or I need an additional errors | validations arg on (e/fn [form ?errors _id] ...) I can look up multiple error messages via Input!'s :key. May require coercion of server error result.
the question is how to map errors back to specific fields from the command handler. So everything's been validated and the user submits the form and the form command fails. E.g. an external service deems an e-mail address blacklisted. forms5 handles the command failure and the user can show the error at the form level, but can one show the error on the field level?
Showing error at the field level can be done at field validation time by validating fields independently (via field :Parse). Auto-mapping a derived tx error back onto the original field is a difficult problem. It would require keeping track of data origin across tx transformations. Doing this generically and robustly implies tagged unions, fibrations, and other niceties. We ruled it out of scope for now, as we wanted txs to be values. If your system is able to produce a mapping of error → original field, then you can loop it back through an atom (e.g. by intercepting the token with TrackTx) and render it next to you form field.
I've clobbered together a solution by returning [::form/fail ex-message ex-data] from my own try-ok, and ensuring that ex-data is serializable with a human-readable map of Malli field errors, which I pass down into my input helpers, which look for errors pertaining to that field, and render them next to the field.
If I understand correctly, something like the following should work.