@@ -224,7 +224,7 @@ async function _clientValidation<T extends AnyZodObject, M = unknown>(
224224 */
225225export async function validateObjectErrors < T extends AnyZodObject , M > (
226226 formOptions : FormOptions < T , M > ,
227- data : z . infer < T > ,
227+ Form : SuperForm < T , M > [ 'form' ] ,
228228 Errors : SuperForm < T , M > [ 'errors' ] ,
229229 tainted : TaintedFields < UnwrapEffects < T > > | undefined
230230) {
@@ -236,7 +236,7 @@ export async function validateObjectErrors<T extends AnyZodObject, M>(
236236 }
237237
238238 const validators = formOptions . validators as AnyZodObject ;
239- const result = await validators . safeParseAsync ( data ) ;
239+ const result = await validators . safeParseAsync ( get ( Form ) ) ;
240240
241241 if ( ! result . success ) {
242242 const newErrors = mapErrors (
@@ -281,13 +281,15 @@ export async function validateObjectErrors<T extends AnyZodObject, M>(
281281 } ) ;
282282 return currentErrors ;
283283 } ) ;
284+ // Disable if form values shouldn't be updated immediately:
285+ if ( result . data ) Form . set ( result . data ) ;
284286 }
285287}
286288
287289type ValidationResult < T extends ZodValidation < AnyZodObject > > = {
288290 validated : boolean | 'all' ;
289291 errors : string [ ] | undefined ;
290- data : SuperForm < T , unknown > [ 'form' ] | undefined ;
292+ data : z . infer < T > | undefined ;
291293} ;
292294
293295/**
@@ -344,7 +346,7 @@ export async function validateField<
344346 return errorMsgs ?? undefined ;
345347 }
346348
347- const errors = await _validateField (
349+ const result = await _validateField (
348350 path ,
349351 formOptions . validators ,
350352 data ,
@@ -353,25 +355,25 @@ export async function validateField<
353355 options
354356 ) ;
355357
356- if ( errors . validated ) {
357- if ( errors . validated === 'all' && ! errors . errors ) {
358+ if ( result . validated ) {
359+ if ( result . validated === 'all' && ! result . errors ) {
358360 // We validated the whole data structure, so clear all errors on success after delayed validators.
359361 // it will also set the current path to undefined, so it can be used in
360362 // the tainted+error check in oninput.
361363 Errors_clear ( ) ;
362364 } else {
363- errors . errors = Errors_update ( errors . errors ) ;
364- return errors ;
365+ result . errors = Errors_update ( result . errors ) ;
365366 }
366367 } else if (
367- errors . validated === false &&
368+ result . validated === false &&
368369 formOptions . defaultValidator == 'clear'
369370 ) {
370- errors . errors = Errors_update ( errors . errors ) ;
371- return errors ;
371+ result . errors = Errors_update ( result . errors ) ;
372372 }
373373
374- return errors ;
374+ if ( result . data ) data . set ( result . data , options ) ;
375+
376+ return result ;
375377}
376378
377379// @DCI -context
0 commit comments