Closed ciscoheat closed 1 year ago
Got a nice suggestion on the discord to make a derived store that intersects $tainted
and $errors
. I wonder if this is enough...!
Validating data is only part of the process. We'll still need some piece of code to react to input losing focus if no data has changed, like tabbing away from an empty input. Intersecting $tainted
and $errors
is good approach, but additional store has to track touched inputs, to not show errors on inputs which user has not visited yet.
Fixed now with v0.8! Announcement: https://github.com/ciscoheat/sveltekit-superforms/discussions/106
Discussed in https://github.com/ciscoheat/sveltekit-superforms/discussions/45
The main issue
The problem with making validation work with a pattern like reward early, validate late is that Superforms aren't using any form events, it knows nothing about the form that you're using its store properties on. This is what makes it easy to use, but poses a problem when it comes to events like
on:blur
andon:input
. Adding those events manually to every form field is not viable, so the next option would be to add those events to the form itself, using the bubbling phase to determine what happened.This would have worked fine for top-level fields, but the data can be nested, so if you're outputting an array of tags:
Then the
input
event don't know that the changed field is bound to$form.user.tags[i]
, which is what is needed to locate the correct validator, which could look like:The
$tainted
store comes to mind, which accurately keeps track of each field that has changed. Maybe it can be used on eachinput/blur/etc
event to diff its previous state, thereby determining which field(s) changed on each event.Any ideas about this is appreciated!