sveltekit-superforms icon indicating copy to clipboard operation
sveltekit-superforms copied to clipboard

return data from adapter's `validate` even if validation isn't successful

Open alex-pirogov opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. I'm using valibot adapter which also supports transformations. Consider the schema:

const schema = v.object({
	email: v.pipe(v.string(), v.trim(), v.toLowerCase(), v.email())
})

If my form's data looks like this:

{ email: '      foobar' }

then validation obviously fails, but transformations are not applied as data is returned only if validation is successful. Valibot's validation result at the same time is:

output: {
    email: "foobar"
}

Describe the solution you'd like In some cases it would be great to apply invalid validation output to form data. This will allow easily create forms which modify user's input on-the-fly

alex-pirogov avatar Nov 21 '24 13:11 alex-pirogov

This is how all adapters and validation libraries work, the idea is that you want to preserve user data to avoid surprises. Modifying data before the submit process is successful can produce a worse UX. But of course there are exceptions, so if you'd like to do that, I suggest making a separate validation with the schema itself.

ciscoheat avatar Dec 01 '24 05:12 ciscoheat