@@ -609,6 +609,44 @@ export function superForm<
609609 return obj === true ;
610610 }
611611
612+ function Tainted__validate ( path : string [ ] , taint : TaintOption ) {
613+ if (
614+ options . validationMethod == 'onblur' ||
615+ options . validationMethod == 'submit-only'
616+ ) {
617+ return ;
618+ }
619+
620+ let shouldValidate = options . validationMethod === 'oninput' ;
621+
622+ if ( ! shouldValidate ) {
623+ const errorContent = get ( Errors ) ;
624+
625+ const errorNode = errorContent
626+ ? pathExists ( errorContent , path )
627+ : undefined ;
628+
629+ // Need a special check here, since if the error has never existed,
630+ // there won't be a key for the error. But if it existed and was cleared,
631+ // the key exists with the value undefined.
632+ const hasError = errorNode && errorNode . key in errorNode . parent ;
633+
634+ shouldValidate = ! ! hasError ;
635+ }
636+
637+ if ( shouldValidate ) {
638+ validateField (
639+ path ,
640+ options . validators ,
641+ options . defaultValidator ,
642+ Form ,
643+ Errors ,
644+ Tainted ,
645+ { taint }
646+ ) ;
647+ }
648+ }
649+
612650 function Tainted_update (
613651 newObj : unknown ,
614652 compareAgainst : unknown ,
@@ -634,6 +672,11 @@ export function superForm<
634672 setPaths ( tainted , paths , options === true ? true : undefined ) ;
635673 return tainted ;
636674 } ) ;
675+
676+ for ( const path of paths ) {
677+ //console.log('🚀 ~ file: index.ts:681 ~ path:', path);
678+ Tainted__validate ( path , options ) ;
679+ }
637680 }
638681 }
639682
@@ -1264,51 +1307,6 @@ function formEnhance<T extends AnyZodObject, M>(
12641307 }
12651308 formEl . addEventListener ( 'focusout' , checkBlur ) ;
12661309
1267- // Add input event, to check tainted
1268- async function checkInput ( e : Event ) {
1269- if (
1270- options . validationMethod == 'onblur' ||
1271- options . validationMethod == 'submit-only'
1272- ) {
1273- return ;
1274- }
1275-
1276- // Some form fields have some timing issue, need to wait
1277- if ( timingIssue ( e . target ) ) {
1278- await new Promise ( ( r ) => setTimeout ( r , 0 ) ) ;
1279- }
1280-
1281- const errorContent = get ( errors ) ;
1282- const taintedContent = get ( tainted ) ;
1283-
1284- for ( const change of get ( lastChanges ) ) {
1285- let shouldValidate = options . validationMethod === 'oninput' ;
1286-
1287- if ( ! shouldValidate ) {
1288- const isTainted =
1289- taintedContent &&
1290- pathExists ( taintedContent , change , ( value ) => value === true ) ;
1291-
1292- const errorNode = errorContent
1293- ? pathExists ( errorContent , change )
1294- : undefined ;
1295-
1296- // Need a special check here, since if the error has never existed,
1297- // there won't be a key for the error. But if it existed and was cleared,
1298- // the key exists with the value undefined.
1299- const hasError = errorNode && errorNode . key in errorNode . parent ;
1300-
1301- shouldValidate = ! ! isTainted && ! ! hasError ;
1302- }
1303-
1304- if ( shouldValidate ) {
1305- //console.log('🚀 ~ file: index.ts:920 ~ INPUT with error:', change);
1306- validateChange ( change ) ;
1307- }
1308- }
1309- }
1310- formEl . addEventListener ( 'input' , checkInput ) ;
1311-
13121310 const ErrorTextEvents = new Set < HTMLFormElement > ( ) ;
13131311
13141312 function ErrorTextEvents_selectText ( e : Event ) {
@@ -1338,7 +1336,6 @@ function formEnhance<T extends AnyZodObject, M>(
13381336 ) ;
13391337 ErrorTextEvents . clear ( ) ;
13401338 formEl . removeEventListener ( 'focusout' , checkBlur ) ;
1341- formEl . removeEventListener ( 'input' , checkInput ) ;
13421339 } ) ;
13431340
13441341 type ValidationResponse <
0 commit comments