@tanstack/form-core
Advanced tools
Comparing version 0.16.2 to 0.18.0
@@ -87,2 +87,3 @@ import { Store } from '@tanstack/store'; | ||
swapValues: (aIndex: number, bIndex: number) => void; | ||
moveValue: (aIndex: number, bIndex: number) => void; | ||
validateSync: (value: TData | undefined, cause: ValidationCause) => { | ||
@@ -89,0 +90,0 @@ hasErrored: boolean; |
@@ -87,2 +87,3 @@ import { Store } from "@tanstack/store"; | ||
this.swapValues = (aIndex, bIndex) => this.form.swapFieldValues(this.name, aIndex, bIndex); | ||
this.moveValue = (aIndex, bIndex) => this.form.moveFieldValues(this.name, aIndex, bIndex); | ||
this.validateSync = (value = this.state.value, cause) => { | ||
@@ -89,0 +90,0 @@ const validates = getSyncValidatorArray(cause, this.options); |
@@ -120,2 +120,3 @@ import { Store } from '@tanstack/store'; | ||
swapFieldValues: <TField extends DeepKeys<TFormData>>(field: TField, index1: number, index2: number) => void; | ||
moveFieldValues: <TField extends DeepKeys<TFormData>>(field: TField, index1: number, index2: number) => void; | ||
} |
@@ -357,2 +357,8 @@ import { Store } from "@tanstack/store"; | ||
}; | ||
this.moveFieldValues = (field, index1, index2) => { | ||
this.setFieldValue(field, (prev) => { | ||
prev.splice(index2, 0, prev.splice(index1, 1)[0]); | ||
return prev; | ||
}); | ||
}; | ||
this.store = new Store( | ||
@@ -359,0 +365,0 @@ getDefaultFormState({ |
{ | ||
"name": "@tanstack/form-core", | ||
"version": "0.16.2", | ||
"version": "0.18.0", | ||
"description": "Powerful, type-safe, framework agnostic forms.", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -485,2 +485,5 @@ import { Store } from '@tanstack/store' | ||
moveValue = (aIndex: number, bIndex: number) => | ||
this.form.moveFieldValues(this.name, aIndex, bIndex) | ||
validateSync = (value = this.state.value, cause: ValidationCause) => { | ||
@@ -487,0 +490,0 @@ const validates = getSyncValidatorArray(cause, this.options) |
@@ -721,2 +721,13 @@ import { Store } from '@tanstack/store' | ||
} | ||
moveFieldValues = <TField extends DeepKeys<TFormData>>( | ||
field: TField, | ||
index1: number, | ||
index2: number, | ||
) => { | ||
this.setFieldValue(field, (prev: any) => { | ||
prev.splice(index2, 0, prev.splice(index1, 1)[0]) | ||
return prev | ||
}) | ||
} | ||
} | ||
@@ -723,0 +734,0 @@ |
@@ -161,2 +161,19 @@ import { describe, expect, it, vi } from 'vitest' | ||
it('should move a value from an array value correctly', () => { | ||
const form = new FormApi({ | ||
defaultValues: { | ||
names: ['one', 'two', 'three', 'four'], | ||
}, | ||
}) | ||
const field = new FieldApi({ | ||
form, | ||
name: 'names', | ||
}) | ||
field.moveValue(2, 0) | ||
expect(field.getValue()).toStrictEqual(['three', 'one', 'two', 'four']) | ||
}) | ||
it('should not throw errors when no meta info is stored on a field and a form re-renders', async () => { | ||
@@ -163,0 +180,0 @@ const form = new FormApi({ |
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
351061
5815