@tanstack/form-core
Advanced tools
Comparing version 0.34.4 to 0.35.0
@@ -285,4 +285,10 @@ import { Store } from '@tanstack/store'; | ||
* Resets the form state to the default values. | ||
* If values are provided, the form will be reset to those values instead and the default values will be updated. | ||
* | ||
* @param values - Optional values to reset the form to. | ||
* @param opts - Optional options to control the reset behavior. | ||
*/ | ||
reset: () => void; | ||
reset: (values?: TFormData, opts?: { | ||
keepDefaultValues?: boolean; | ||
}) => void; | ||
/** | ||
@@ -289,0 +295,0 @@ * Validates all fields in the form using the correct handlers for a given validation type. |
@@ -84,5 +84,11 @@ import { Store } from "@tanstack/store"; | ||
}; | ||
this.reset = () => { | ||
this.reset = (values, opts2) => { | ||
const { fieldMeta: currentFieldMeta } = this.state; | ||
const fieldMeta = this.resetFieldMeta(currentFieldMeta); | ||
if (values && !(opts2 == null ? void 0 : opts2.keepDefaultValues)) { | ||
this.options = { | ||
...this.options, | ||
defaultValues: values | ||
}; | ||
} | ||
this.store.setState( | ||
@@ -93,3 +99,3 @@ () => { | ||
...this.options.defaultState, | ||
values: this.options.defaultValues ?? ((_a2 = this.options.defaultState) == null ? void 0 : _a2.values), | ||
values: values ?? this.options.defaultValues ?? ((_a2 = this.options.defaultState) == null ? void 0 : _a2.values), | ||
fieldMeta | ||
@@ -96,0 +102,0 @@ }); |
{ | ||
"name": "@tanstack/form-core", | ||
"version": "0.34.4", | ||
"version": "0.35.0", | ||
"description": "Powerful, type-safe, framework agnostic forms.", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -575,10 +575,25 @@ import { Store } from '@tanstack/store' | ||
* Resets the form state to the default values. | ||
* If values are provided, the form will be reset to those values instead and the default values will be updated. | ||
* | ||
* @param values - Optional values to reset the form to. | ||
* @param opts - Optional options to control the reset behavior. | ||
*/ | ||
reset = () => { | ||
reset = (values?: TFormData, opts?: { keepDefaultValues?: boolean }) => { | ||
const { fieldMeta: currentFieldMeta } = this.state | ||
const fieldMeta = this.resetFieldMeta(currentFieldMeta) | ||
if (values && !opts?.keepDefaultValues) { | ||
this.options = { | ||
...this.options, | ||
defaultValues: values, | ||
} | ||
} | ||
this.store.setState(() => | ||
getDefaultFormState({ | ||
...(this.options.defaultState as any), | ||
values: this.options.defaultValues ?? this.options.defaultState?.values, | ||
values: | ||
values ?? | ||
this.options.defaultValues ?? | ||
this.options.defaultState?.values, | ||
fieldMeta, | ||
@@ -585,0 +600,0 @@ }), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
476901
6298