Context
When working with a schema containing transforms, it happens that the raw values types in the form don't match the schema.parse return type. This is the case in the checkboxes example documented in the readme where the type of the "input" is undefined|string and the resulting value is of type boolean. This also happen when working with text inputs storing arrays of values for example:
<input type="text" value="value1,value2"/>
Problem
With the following schema:
const FormSchema = z.object({
myarray: z.string().transform(strValues => strValues.split(',')).pipe(z.array(z.string()))
})
The type of zo.fields.myarray is generated from the parse output type (string[] in that case). Which leads to the compiler not allowing to call zo.fields.myarray without an index argument:
<input type="text" name={zo.fields.myarray()/*Error: An argument for 'index' was not provided*/}value="value1,value2"/>
Solution
Changing this line so that the FieldChain is computed from the parse input instead of the parse result would fix this.
export declare type FieldChainFromSchema<T extends GenericSchema> = FieldChain<DeepNonNullable<z.input<T>>>;
The change should probably also be applied to the ErrorChainFromSchema type.
I can make a PR if you want. :)
Context
When working with a schema containing transforms, it happens that the raw values types in the form don't match the
schema.parsereturn type. This is the case in the checkboxes example documented in the readme where the type of the "input" isundefined|stringand the resulting value is of typeboolean. This also happen when working with text inputs storing arrays of values for example:Problem
With the following schema:
The type of
zo.fields.myarrayis generated from the parse output type (string[]in that case). Which leads to the compiler not allowing to callzo.fields.myarraywithout anindexargument:Solution
Changing this line so that the FieldChain is computed from the parse input instead of the parse result would fix this.
The change should probably also be applied to the
ErrorChainFromSchematype.I can make a PR if you want. :)