@@ -62,7 +62,7 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
6262 /**
6363 * Patch the form.
6464 */
65- return Object . assign ( inertiaForm , {
65+ const form = Object . assign ( inertiaForm , {
6666 validating : precognitiveForm . validating ,
6767 touched : precognitiveForm . touched ,
6868 valid : precognitiveForm . valid ,
@@ -72,7 +72,7 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
7272
7373 precognitiveForm . setData ( key , value )
7474
75- return this
75+ return form
7676 } ,
7777 clearErrors ( ...names : string [ ] ) {
7878 inertiaClearErrors ( ...names )
@@ -83,7 +83,7 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
8383 names . forEach ( precognitiveForm . forgetError )
8484 }
8585
86- return this
86+ return form
8787 } ,
8888 reset ( ...names : string [ ] ) {
8989 inertiaReset ( ...names )
@@ -94,39 +94,39 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
9494 // @ts -expect-error
9595 precognitiveForm . setErrors ( errors )
9696
97- return this
97+ return form
9898 } ,
9999 setError ( key : any , value ?: any ) {
100- this . setErrors ( {
100+ form . setErrors ( {
101101 ...inertiaForm . errors ,
102102 ...typeof value === 'undefined'
103103 ? key
104104 : { [ key ] : value } ,
105105 } )
106106
107- return this
107+ return form
108108 } ,
109109 forgetError ( name : string | NamedInputEvent ) {
110110 precognitiveForm . forgetError ( name )
111111
112- return this
112+ return form
113113 } ,
114114 validate ( name : string | NamedInputEvent ) {
115115 precognitiveForm . setData ( inertiaForm . data )
116116
117117 precognitiveForm . validate ( name )
118118
119- return this
119+ return form
120120 } ,
121121 setValidationTimeout ( duration : number ) {
122122 precognitiveForm . setValidationTimeout ( duration )
123123
124- return this
124+ return form
125125 } ,
126126 validateFiles ( ) {
127127 precognitiveForm . validateFiles ( )
128128
129- return this
129+ return form
130130 } ,
131131 submit ( submitMethod : RequestMethod | Config = { } , submitUrl ?: string , submitOptions ?: any ) : void {
132132 const isPatchedCall = typeof submitMethod !== 'string'
@@ -156,4 +156,6 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
156156 } ,
157157 validator : precognitiveForm . validator ,
158158 } )
159+
160+ return form
159161}
0 commit comments