@@ -82,7 +82,7 @@ export interface FormOptions<
8282 TOutput = TValues ,
8383 TSchema extends TypedSchema < TValues , TOutput > | FormSchema < TValues > =
8484 | FormSchema < TValues >
85- | TypedSchema < TValues , TOutput >
85+ | TypedSchema < TValues , TOutput > ,
8686> {
8787 validationSchema ?: MaybeRef < TSchema extends TypedSchema ? TypedSchema < TValues , TOutput > : any > ;
8888 initialValues ?: MaybeRef < PartialDeep < TValues > | undefined | null > ;
@@ -111,7 +111,7 @@ export function useForm<
111111 TOutput = TValues ,
112112 TSchema extends FormSchema < TValues > | TypedSchema < TValues , TOutput > =
113113 | FormSchema < TValues >
114- | TypedSchema < TValues , TOutput >
114+ | TypedSchema < TValues , TOutput > ,
115115> ( opts ?: FormOptions < TValues , TOutput , TSchema > ) : FormContext < TValues , TOutput > {
116116 const formId = FORM_COUNTER ++ ;
117117
@@ -201,19 +201,25 @@ export function useForm<
201201 * Holds a computed reference to all fields names and labels
202202 */
203203 const fieldNames = computed ( ( ) => {
204- return pathStates . value . reduce ( ( names , state ) => {
205- names [ state . path ] = { name : state . path || '' , label : state . label || '' } ;
204+ return pathStates . value . reduce (
205+ ( names , state ) => {
206+ names [ state . path ] = { name : state . path || '' , label : state . label || '' } ;
206207
207- return names ;
208- } , { } as Record < string , { name : string ; label : string } > ) ;
208+ return names ;
209+ } ,
210+ { } as Record < string , { name : string ; label : string } > ,
211+ ) ;
209212 } ) ;
210213
211214 const fieldBailsMap = computed ( ( ) => {
212- return pathStates . value . reduce ( ( map , state ) => {
213- map [ state . path ] = state . bails ?? true ;
215+ return pathStates . value . reduce (
216+ ( map , state ) => {
217+ map [ state . path ] = state . bails ?? true ;
214218
215- return map ;
216- } , { } as Record < string , boolean > ) ;
219+ return map ;
220+ } ,
221+ { } as Record < string , boolean > ,
222+ ) ;
217223 } ) ;
218224
219225 // mutable non-reactive reference to initial errors
@@ -228,7 +234,7 @@ export function useForm<
228234 const { initialValues, originalInitialValues, setInitialValues } = useFormInitialValues < TValues > (
229235 pathStates ,
230236 formValues ,
231- opts
237+ opts ,
232238 ) ;
233239
234240 // form meta aggregations
@@ -247,7 +253,7 @@ export function useForm<
247253
248254 function createPathState < TValue > (
249255 path : MaybeRefOrGetter < Path < TValues > > ,
250- config ?: Partial < PathStateConfig >
256+ config ?: Partial < PathStateConfig > ,
251257 ) : PathState < TValue > {
252258 const initialValue = computed ( ( ) => getFromPath ( initialValues . value , toValue ( path ) ) ) ;
253259 const pathStateExists = pathStates . value . find ( s => isPathsEqual ( s . path , toValue ( path ) ) ) ;
@@ -380,9 +386,9 @@ export function useForm<
380386
381387 return validation ;
382388 } ,
383- { valid : formResult . valid , results : { } , errors : { } } as FormValidationResult < TValues >
389+ { valid : formResult . valid , results : { } , errors : { } } as FormValidationResult < TValues > ,
384390 ) ;
385- }
391+ } ,
386392 ) ;
387393
388394 function mutateAllPathState ( mutation : ( state : PathState ) => void ) {
@@ -398,15 +404,18 @@ export function useForm<
398404 function findHoistedPath ( path : Path < TValues > ) {
399405 const candidates = pathStates . value . filter ( state => path . startsWith ( state . path ) ) ;
400406
401- return candidates . reduce ( ( bestCandidate , candidate ) => {
402- if ( ! bestCandidate ) {
403- return candidate as PathState < PathValue < TValues , Path < TValues > > > ;
404- }
407+ return candidates . reduce (
408+ ( bestCandidate , candidate ) => {
409+ if ( ! bestCandidate ) {
410+ return candidate as PathState < PathValue < TValues , Path < TValues > > > ;
411+ }
405412
406- return ( candidate . path . length > bestCandidate . path . length ? candidate : bestCandidate ) as PathState <
407- PathValue < TValues , Path < TValues > >
408- > ;
409- } , undefined as PathState < PathValue < TValues , Path < TValues > > > | undefined ) ;
413+ return ( candidate . path . length > bestCandidate . path . length ? candidate : bestCandidate ) as PathState <
414+ PathValue < TValues , Path < TValues > >
415+ > ;
416+ } ,
417+ undefined as PathState < PathValue < TValues , Path < TValues > > > | undefined ,
418+ ) ;
410419 }
411420
412421 let UNSET_BATCH : Path < TValues > [ ] = [ ] ;
@@ -431,7 +440,7 @@ export function useForm<
431440 function makeSubmissionFactory ( onlyControlled : boolean ) {
432441 return function submitHandlerFactory < TReturn = unknown > (
433442 fn ?: SubmissionHandler < TValues , TOutput , TReturn > ,
434- onValidationError ?: InvalidSubmissionHandler < TValues >
443+ onValidationError ?: InvalidSubmissionHandler < TValues > ,
435444 ) {
436445 return function submissionHandler ( e : unknown ) {
437446 if ( e instanceof Event ) {
@@ -489,7 +498,7 @@ export function useForm<
489498
490499 // re-throw the err so it doesn't go silent
491500 throw err ;
492- }
501+ } ,
493502 ) ;
494503 } ;
495504 } ;
@@ -507,7 +516,7 @@ export function useForm<
507516 }
508517
509518 nextTick ( ( ) => {
510- validateField ( path , { mode : 'silent' } ) ;
519+ validateField ( path , { mode : 'silent' , warn : false } ) ;
511520 } ) ;
512521
513522 if ( pathState . multiple && pathState . fieldsCount ) {
@@ -583,7 +592,7 @@ export function useForm<
583592 function setFieldValue < T extends Path < TValues > > (
584593 field : T | PathState ,
585594 value : PathValue < TValues , T > | undefined ,
586- shouldValidate = true
595+ shouldValidate = true ,
587596 ) {
588597 const clonedValue = deepCopy ( value ) ;
589598 const path = typeof field === 'string' ? field : ( field . path as Path < TValues > ) ;
@@ -632,7 +641,7 @@ export function useForm<
632641
633642 function useFieldModel < TPath extends Path < TValues > > ( path : TPath ) : Ref < PathValue < TValues , TPath > > ;
634643 function useFieldModel < TPaths extends readonly [ ...MaybeRef < Path < TValues > > [ ] ] > (
635- paths : TPaths
644+ paths : TPaths ,
636645 ) : MapValuesPathsToRefs < TValues , TPaths > ;
637646 function useFieldModel < TPaths extends Path < TValues > | readonly [ ...MaybeRef < Path < TValues > > [ ] ] > ( pathOrPaths : TPaths ) {
638647 if ( ! Array . isArray ( pathOrPaths ) ) {
@@ -723,7 +732,7 @@ export function useForm<
723732 errors : result . errors ,
724733 } ;
725734 } ) ;
726- } )
735+ } ) ,
727736 ) ;
728737
729738 isValidating . value = false ;
@@ -764,7 +773,8 @@ export function useForm<
764773 return state . validate ( opts ) ;
765774 }
766775
767- if ( ! state ) {
776+ const shouldWarn = ! state && ( opts ?. warn ?? true ) ;
777+ if ( shouldWarn ) {
768778 warn ( `field with path ${ path } was not found` ) ;
769779 }
770780
@@ -863,17 +873,17 @@ export function useForm<
863873 refreshInspector ,
864874 {
865875 deep : true ,
866- }
876+ } ,
867877 ) ;
868878 }
869879
870880 function defineComponentBinds <
871881 TPath extends Path < TValues > ,
872882 TValue = PathValue < TValues , TPath > ,
873- TExtras extends GenericObject = GenericObject
883+ TExtras extends GenericObject = GenericObject ,
874884 > (
875885 path : MaybeRefOrGetter < TPath > ,
876- config ?: Partial < ComponentBindsConfig < TValue , TExtras > > | LazyComponentBindsConfig < TValue , TExtras >
886+ config ?: Partial < ComponentBindsConfig < TValue , TExtras > > | LazyComponentBindsConfig < TValue , TExtras > ,
877887 ) {
878888 const pathState = findPathState ( toValue ( path ) ) || createPathState ( path ) ;
879889 const evalConfig = ( ) => ( isCallable ( config ) ? config ( omit ( pathState , PRIVATE_PATH_STATE_KEYS ) ) : config || { } ) ;
@@ -927,10 +937,10 @@ export function useForm<
927937 function defineInputBinds <
928938 TPath extends Path < TValues > ,
929939 TValue = PathValue < TValues , TPath > ,
930- TExtras extends GenericObject = GenericObject
940+ TExtras extends GenericObject = GenericObject ,
931941 > (
932942 path : MaybeRefOrGetter < TPath > ,
933- config ?: Partial < InputBindsConfig < TValue , TExtras > > | LazyInputBindsConfig < TValue , TExtras >
943+ config ?: Partial < InputBindsConfig < TValue , TExtras > > | LazyInputBindsConfig < TValue , TExtras > ,
934944 ) {
935945 const pathState = ( findPathState ( toValue ( path ) ) || createPathState ( path ) ) as PathState < TValue > ;
936946 const evalConfig = ( ) => ( isCallable ( config ) ? config ( omit ( pathState , PRIVATE_PATH_STATE_KEYS ) ) : config || { } ) ;
@@ -1000,7 +1010,7 @@ function useFormMeta<TValues extends Record<string, unknown>>(
10001010 pathsState : Ref < PathState < unknown > [ ] > ,
10011011 currentValues : TValues ,
10021012 initialValues : MaybeRef < PartialDeep < TValues > > ,
1003- errors : Ref < FormErrors < TValues > >
1013+ errors : Ref < FormErrors < TValues > > ,
10041014) {
10051015 const MERGE_STRATEGIES : Record < keyof Pick < FieldMeta < unknown > , 'touched' | 'pending' | 'valid' > , 'every' | 'some' > = {
10061016 touched : 'some' ,
@@ -1015,12 +1025,15 @@ function useFormMeta<TValues extends Record<string, unknown>>(
10151025 function calculateFlags ( ) {
10161026 const states = pathsState . value ;
10171027
1018- return keysOf ( MERGE_STRATEGIES ) . reduce ( ( acc , flag ) => {
1019- const mergeMethod = MERGE_STRATEGIES [ flag ] ;
1020- acc [ flag ] = states [ mergeMethod ] ( s => s [ flag ] ) ;
1028+ return keysOf ( MERGE_STRATEGIES ) . reduce (
1029+ ( acc , flag ) => {
1030+ const mergeMethod = MERGE_STRATEGIES [ flag ] ;
1031+ acc [ flag ] = states [ mergeMethod ] ( s => s [ flag ] ) ;
10211032
1022- return acc ;
1023- } , { } as Record < keyof Omit < FieldMeta < unknown > , 'initialValue' > , boolean > ) ;
1033+ return acc ;
1034+ } ,
1035+ { } as Record < keyof Omit < FieldMeta < unknown > , 'initialValue' > , boolean > ,
1036+ ) ;
10241037 }
10251038
10261039 const flags = reactive ( calculateFlags ( ) ) ;
@@ -1048,7 +1061,7 @@ function useFormMeta<TValues extends Record<string, unknown>>(
10481061function useFormInitialValues < TValues extends GenericObject > (
10491062 pathsState : Ref < PathState < unknown > [ ] > ,
10501063 formValues : TValues ,
1051- opts ?: FormOptions < TValues >
1064+ opts ?: FormOptions < TValues > ,
10521065) {
10531066 const values = resolveInitialValues ( opts ) as PartialDeep < TValues > ;
10541067 const providedValues = opts ?. initialValues ;
@@ -1094,7 +1107,7 @@ function useFormInitialValues<TValues extends GenericObject>(
10941107 } ,
10951108 {
10961109 deep : true ,
1097- }
1110+ } ,
10981111 ) ;
10991112 }
11001113
0 commit comments