@@ -188,7 +188,11 @@ type SuperFormSnapshot<T extends AnyZodObject, M = any> = SuperValidated<
188188 M
189189> & { tainted : TaintedFields < T > | undefined } ;
190190
191- export type TaintOption = boolean | 'untaint' | 'untaint-all' ;
191+ export type TaintOption < T extends AnyZodObject = AnyZodObject > =
192+ | boolean
193+ | 'untaint'
194+ | 'untaint-all'
195+ | { fields : FormPathLeaves < z . infer < T > > | FormPathLeaves < z . infer < T > > [ ] } ;
192196
193197// eslint-disable-next-line @typescript-eslint/no-explicit-any
194198export type SuperForm < T extends ZodValidation < AnyZodObject > , M = any > = {
@@ -197,12 +201,12 @@ export type SuperForm<T extends ZodValidation<AnyZodObject>, M = any> = {
197201 set (
198202 this : void ,
199203 value : z . infer < UnwrapEffects < T > > ,
200- options ?: { taint ?: TaintOption }
204+ options ?: { taint ?: TaintOption < UnwrapEffects < T > > }
201205 ) : void ;
202206 update (
203207 this : void ,
204208 updater : Updater < z . infer < UnwrapEffects < T > > > ,
205- options ?: { taint ?: TaintOption }
209+ options ?: { taint ?: TaintOption < UnwrapEffects < T > > }
206210 ) : void ;
207211 } ;
208212 formId : Writable < string | undefined > ;
@@ -417,7 +421,7 @@ export function superForm<
417421 subscribe : _formData . subscribe ,
418422 set : (
419423 value : Parameters < typeof _formData . set > [ 0 ] ,
420- options : { taint ?: TaintOption } = { }
424+ options : { taint ?: TaintOption < UnwrappedT > } = { }
421425 ) => {
422426 Tainted_update (
423427 value ,
@@ -429,7 +433,7 @@ export function superForm<
429433 } ,
430434 update : (
431435 updater : Parameters < typeof _formData . update > [ 0 ] ,
432- options : { taint ?: TaintOption } = { }
436+ options : { taint ?: TaintOption < UnwrappedT > } = { }
433437 ) => {
434438 return _formData . update ( ( value ) => {
435439 const output = updater ( value ) ;
@@ -593,7 +597,10 @@ export function superForm<
593597 return obj === true ;
594598 }
595599
596- async function Tainted__validate ( path : string [ ] , taint : TaintOption ) {
600+ async function Tainted__validate (
601+ path : string [ ] ,
602+ taint : TaintOption < UnwrappedT >
603+ ) {
597604 if (
598605 options . validationMethod == 'onblur' ||
599606 options . validationMethod == 'submit-only'
@@ -641,7 +648,7 @@ export function superForm<
641648 async function Tainted_update (
642649 newObj : unknown ,
643650 compareAgainst : unknown ,
644- taintOptions : TaintOption
651+ taintOptions : TaintOption < UnwrappedT >
645652 ) {
646653 if ( taintOptions === false ) {
647654 return ;
@@ -650,7 +657,18 @@ export function superForm<
650657 return ;
651658 }
652659
653- const paths = comparePaths ( newObj , compareAgainst ) ;
660+ let paths = comparePaths ( newObj , compareAgainst ) ;
661+
662+ if ( typeof taintOptions === 'object' ) {
663+ if ( typeof taintOptions . fields === 'string' )
664+ taintOptions . fields = [ taintOptions . fields ] ;
665+
666+ paths = taintOptions . fields . map ( ( path ) =>
667+ splitPath ( path )
668+ ) as string [ ] [ ] ;
669+
670+ taintOptions = true ;
671+ }
654672
655673 if ( taintOptions === true ) {
656674 LastChanges . set ( paths ) ;
@@ -827,7 +845,10 @@ export function superForm<
827845
828846 function validate < Path extends FormPathLeaves < z . infer < UnwrapEffects < T > > > > (
829847 path ?: Path ,
830- opts ?: ValidateOptions < FormPathType < z . infer < UnwrapEffects < T > > , Path > >
848+ opts ?: ValidateOptions <
849+ FormPathType < z . infer < UnwrapEffects < T > > , Path > ,
850+ UnwrapEffects < T >
851+ >
831852 ) {
832853 if ( path === undefined ) {
833854 return clientValidation < UnwrapEffects < T > , M > (
@@ -881,7 +902,7 @@ export function superForm<
881902 return rebind ( snapshot , snapshot . tainted ?? true ) ;
882903 } ,
883904
884- validate : validate as typeof validateForm < UnwrapEffects < T > > ,
905+ validate : validate as typeof validateForm < UnwrappedT > ,
885906
886907 enhance : (
887908 el : HTMLFormElement ,
0 commit comments