@tanstack/form-core
Advanced tools
Comparing version 0.23.3 to 0.24.0
@@ -118,3 +118,2 @@ import { Store } from '@tanstack/store'; | ||
asyncAlways?: boolean; | ||
preserveValue?: boolean; | ||
/** | ||
@@ -121,0 +120,0 @@ * A validator provided by an extension, like `yupValidator` from `@tanstack/yup-form-adapter` |
@@ -44,7 +44,3 @@ import { Store } from "@tanstack/store"; | ||
return () => { | ||
const preserveValue = this.options.preserveValue; | ||
unsubscribe(); | ||
if (!preserveValue) { | ||
this.form.deleteField(this.name); | ||
} | ||
}; | ||
@@ -64,5 +60,2 @@ }; | ||
} | ||
if (opts2.defaultValue === void 0 && this.form._tempDefaultValue !== void 0 && this.form._tempDefaultValue.field === this.name) { | ||
opts2.defaultValue = this.form._tempDefaultValue.value; | ||
} | ||
this.options = opts2; | ||
@@ -295,5 +288,2 @@ }; | ||
this.name = opts.name; | ||
if (opts.defaultValue === void 0 && this.form._tempDefaultValue !== void 0 && this.form._tempDefaultValue.field === this.name) { | ||
opts.defaultValue = this.form._tempDefaultValue.value; | ||
} | ||
if (opts.defaultValue !== void 0) { | ||
@@ -326,7 +316,2 @@ this.form.setFieldValue(this.name, opts.defaultValue); | ||
this.state = state; | ||
setTimeout(() => { | ||
if (this.form._tempDefaultValue !== void 0 && this.form._tempDefaultValue.field === this.name) { | ||
this.form._tempDefaultValue = void 0; | ||
} | ||
}, 0); | ||
} | ||
@@ -333,0 +318,0 @@ } |
@@ -245,12 +245,2 @@ import { Store } from '@tanstack/store'; | ||
/** | ||
* @private | ||
* Used to handle the edgecase of `pushFieldValue` not adding a `defaultValue` to the child `FieldAPI`s that are | ||
* subsequently generated from the `pushFieldValue` (and friends) | ||
* @see https://github.com/TanStack/form/issues/704#issuecomment-2184080607 | ||
*/ | ||
_tempDefaultValue: undefined | { | ||
field: string; | ||
value: unknown; | ||
}; | ||
/** | ||
* Constructs a new `FormApi` instance with the given form options. | ||
@@ -257,0 +247,0 @@ */ |
@@ -40,3 +40,2 @@ import { Store } from "@tanstack/store"; | ||
this.prevTransformArray = []; | ||
this._tempDefaultValue = void 0; | ||
this.mount = () => { | ||
@@ -381,7 +380,2 @@ const { onMount } = this.options.validators || {}; | ||
this.pushFieldValue = (field, value, opts2) => { | ||
const fieldVal = this.getFieldValue(field) ?? []; | ||
this._tempDefaultValue = { | ||
value, | ||
field: `${field}[${fieldVal.length}]` | ||
}; | ||
this.setFieldValue( | ||
@@ -395,3 +389,2 @@ field, | ||
this.insertFieldValue = async (field, index, value, opts2) => { | ||
this._tempDefaultValue = { value, field: `${field}[${index}]` }; | ||
this.setFieldValue( | ||
@@ -411,3 +404,2 @@ field, | ||
this.replaceFieldValue = async (field, index, value, opts2) => { | ||
this._tempDefaultValue = { value, field: `${field}[${index}]` }; | ||
this.setFieldValue( | ||
@@ -414,0 +406,0 @@ field, |
{ | ||
"name": "@tanstack/form-core", | ||
"version": "0.23.3", | ||
"version": "0.24.0", | ||
"description": "Powerful, type-safe, framework agnostic forms.", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -284,3 +284,2 @@ import { Store } from '@tanstack/store' | ||
asyncAlways?: boolean | ||
preserveValue?: boolean | ||
/** | ||
@@ -449,10 +448,2 @@ * A validator provided by an extension, like `yupValidator` from `@tanstack/yup-form-adapter` | ||
if ( | ||
opts.defaultValue === undefined && | ||
this.form._tempDefaultValue !== undefined && | ||
this.form._tempDefaultValue.field === this.name | ||
) { | ||
opts.defaultValue = this.form._tempDefaultValue.value as never | ||
} | ||
if (opts.defaultValue !== undefined) { | ||
@@ -493,13 +484,2 @@ this.form.setFieldValue(this.name, opts.defaultValue as never) | ||
this.state = state | ||
// Cleanup the temp value after this "tick" | ||
// (Everything occurs sync otherwise) | ||
setTimeout(() => { | ||
if ( | ||
this.form._tempDefaultValue !== undefined && | ||
this.form._tempDefaultValue.field === this.name | ||
) { | ||
this.form._tempDefaultValue = undefined | ||
} | ||
}, 0) | ||
}, | ||
@@ -586,7 +566,3 @@ }, | ||
return () => { | ||
const preserveValue = this.options.preserveValue | ||
unsubscribe() | ||
if (!preserveValue) { | ||
this.form.deleteField(this.name) | ||
} | ||
} | ||
@@ -624,10 +600,2 @@ } | ||
if ( | ||
opts.defaultValue === undefined && | ||
this.form._tempDefaultValue !== undefined && | ||
this.form._tempDefaultValue.field === this.name | ||
) { | ||
opts.defaultValue = this.form._tempDefaultValue.value as never | ||
} | ||
this.options = opts as never | ||
@@ -634,0 +602,0 @@ } |
@@ -342,15 +342,2 @@ import { Store } from '@tanstack/store' | ||
/** | ||
* @private | ||
* Used to handle the edgecase of `pushFieldValue` not adding a `defaultValue` to the child `FieldAPI`s that are | ||
* subsequently generated from the `pushFieldValue` (and friends) | ||
* @see https://github.com/TanStack/form/issues/704#issuecomment-2184080607 | ||
*/ | ||
_tempDefaultValue: | ||
| undefined | ||
| { | ||
field: string | ||
value: unknown | ||
} = undefined | ||
/** | ||
* Constructs a new `FormApi` instance with the given form options. | ||
@@ -960,8 +947,2 @@ */ | ||
) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
const fieldVal = (this.getFieldValue(field) as unknown[]) ?? [] | ||
this._tempDefaultValue = { | ||
value, | ||
field: `${field}[${fieldVal.length}]`, | ||
} as never | ||
this.setFieldValue( | ||
@@ -986,3 +967,2 @@ field, | ||
) => { | ||
this._tempDefaultValue = { value, field: `${field}[${index}]` } as never | ||
this.setFieldValue( | ||
@@ -1015,3 +995,2 @@ field, | ||
) => { | ||
this._tempDefaultValue = { value, field: `${field}[${index}]` } as never | ||
this.setFieldValue( | ||
@@ -1018,0 +997,0 @@ field, |
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
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
415615
5613