@@ -282,6 +282,12 @@ export async function validateObjectErrors<T extends AnyZodObject, M>(
282282 }
283283}
284284
285+ type ValidationResult < T extends ZodValidation < AnyZodObject > > = {
286+ validated : boolean | 'all' ;
287+ errors : string [ ] | undefined ;
288+ data : SuperForm < T , unknown > [ 'form' ] | undefined ;
289+ } ;
290+
285291/**
286292 * Validate a specific form field.
287293 * @DCI -context
@@ -296,7 +302,7 @@ export async function validateField<
296302 Errors : SuperForm < T , M > [ 'errors' ] ,
297303 Tainted : SuperForm < T , M > [ 'tainted' ] ,
298304 options : ValidateOptions < unknown , UnwrapEffects < T > > = { }
299- ) : Promise < string [ ] | undefined > {
305+ ) : Promise < ValidationResult < T > > {
300306 function Errors_clear ( ) {
301307 clearErrors ( Errors , { undefinePath : path , clearFormLevelErrors : true } ) ;
302308 }
@@ -352,16 +358,18 @@ export async function validateField<
352358 // the tainted+error check in oninput.
353359 Errors_clear ( ) ;
354360 } else {
355- return Errors_update ( errors . errors ) ;
361+ errors . errors = Errors_update ( errors . errors ) ;
362+ return errors ;
356363 }
357364 } else if (
358365 errors . validated === false &&
359366 formOptions . defaultValidator == 'clear'
360367 ) {
361- return Errors_update ( undefined ) ;
368+ errors . errors = Errors_update ( errors . errors ) ;
369+ return errors ;
362370 }
363371
364- return errors . errors ;
372+ return errors ;
365373}
366374
367375// @DCI -context
@@ -372,7 +380,7 @@ async function _validateField<T extends ZodValidation<AnyZodObject>, M>(
372380 Errors : SuperForm < T , M > [ 'errors' ] ,
373381 Tainted : SuperForm < T , M > [ 'tainted' ] ,
374382 options : ValidateOptions < unknown , UnwrapEffects < T > > = { }
375- ) : Promise < { validated : boolean | 'all' ; errors : string [ ] | undefined } > {
383+ ) : Promise < ValidationResult < T > > {
376384 if ( options . update === undefined ) options . update = true ;
377385 if ( options . taint === undefined ) options . taint = false ;
378386 if ( typeof options . errors == 'string' ) options . errors = [ options . errors ] ;
@@ -386,7 +394,7 @@ async function _validateField<T extends ZodValidation<AnyZodObject>, M>(
386394 } ;
387395
388396 async function defaultValidate ( ) {
389- return { validated : false , errors : undefined } as const ;
397+ return { validated : false , errors : undefined , data : undefined } as const ;
390398 }
391399
392400 ///// Roles ///////////////////////////////////////////////////////
@@ -516,11 +524,16 @@ async function _validateField<T extends ZodValidation<AnyZodObject>, M>(
516524
517525 return {
518526 validated : true ,
519- errors : options . errors ?? current ?. value
527+ errors : options . errors ?? current ?. value ,
528+ data : undefined
520529 } ;
521530 } else {
522531 Errors_clearAll ( ) ;
523- return { validated : true , errors : undefined } ;
532+ return {
533+ validated : true ,
534+ errors : undefined ,
535+ data : result . data // For a successful Zod result, return the possibly transformed data.
536+ } ;
524537 }
525538 } else {
526539 // SuperForms validator
@@ -539,7 +552,8 @@ async function _validateField<T extends ZodValidation<AnyZodObject>, M>(
539552
540553 return {
541554 validated : true ,
542- errors : result ? options . errors ?? result : result
555+ errors : result ? options . errors ?? result : result ,
556+ data : undefined // No transformation for Superforms validators
543557 } ;
544558 }
545559 }
0 commit comments