@@ -9,12 +9,43 @@ export interface CreateFormObjectOptions<
99 TAdditionalProps ,
1010 TResult extends TData | void = TData ,
1111> {
12+ /**
13+ * Function returning the default values for the form
14+ *
15+ * If not provided, the form will be initialized with an empty object
16+ *
17+ * If `resetDefaultValues` is provided, `defaultValues` will only be used for the initial values
18+ */
1219 defaultValues ?: ( ( ) => Partial < TData > ) | undefined
20+ /**
21+ * Function returning the default values for the form when `$reset()` is called. `resetDefaultValues` is **not** called when initializing the form.
22+ *
23+ * If not provided, `defaultValues` will be used instead
24+ *
25+ * If neither `resetDefaultValues` nor `defaultValues` are provided, the form will be reset to an empty object
26+ */
1327 resetDefaultValues ?: ( ( ) => Awaitable < Partial < TData > > ) | undefined
28+ /**
29+ * Schema to validate the form data against. It should be compatible with Standard Schema v1.
30+ */
1431 schema ?: TSchema
32+ /**
33+ * Function to transform the data before submission (e.g. to remove extra properties).
34+ */
1535 transformData ?: ( data : Partial < TData > ) => Partial < TData >
36+ /**
37+ * Function called when the form is submitted.
38+ */
1639 submit : ( data : Partial < TData > ) => Promise < TResult >
40+ /**
41+ * Additional properties to add to the form object. Their name must start with `$` to avoid conflicts with form fields.
42+ */
1743 additionalProps ?: TAdditionalProps
44+ /**
45+ * Resets the form to default values after a successful submission
46+ * @default true
47+ */
48+ resetOnSuccess ?: boolean
1849}
1950
2051export type FormObjectChanged < TData > = {
@@ -111,7 +142,9 @@ export function createFormObject<
111142 }
112143 const item = await options . submit ( data )
113144 onSuccess . trigger ( item )
114- await form . $reset ( )
145+ if ( options . resetOnSuccess || options . resetOnSuccess == null ) {
146+ await form . $reset ( )
147+ }
115148 return item
116149 }
117150 catch ( error : any ) {
0 commit comments