ui icon indicating copy to clipboard operation
ui copied to clipboard

UForm: apply transformations from the validator

Open 3elDU opened this issue 1 year ago • 2 comments

Description

I'm using Zod for validation, and it has .transform(). For example, you can trim a string:

import { z } from 'zod';
const schema = z.string().trim().min(1, "String must not be empty!");

Now, after running schema.parse(), Zod returns the trimmed string, as expected:

console.log(schema.parse("     a")); // "a"
console.log(schema.parse("b     ")); // "b"

But in the submit event, nuxt ui form provides data directly from the form state, without the transformations. This is hard to call a bug, but at the same time I would expect for the form data to be run through Zod, for all the transformations to apply.

Additional context

No response

3elDU avatar Jul 10 '24 13:07 3elDU

@romhml Is this done in v3 already?

benjamincanac avatar Sep 26 '24 10:09 benjamincanac

Not yet, I'll tackle this one soon

romhml avatar Sep 26 '24 12:09 romhml

Hi, can I work on this issue in v2? @benjamincanac

rdjanuar avatar Oct 24 '24 03:10 rdjanuar

Sure :)

benjamincanac avatar Oct 24 '24 08:10 benjamincanac

thank you @benjamincanac

rdjanuar avatar Oct 24 '24 08:10 rdjanuar