Skip to content

Commit 76cc154

Browse files
committed
feat(FormApi): add array methods carray methods clearValues and filterValues
1 parent 9b31f75 commit 76cc154

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/form-core/tests/FormApi.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,4 +2907,26 @@ describe('form api', () => {
29072907
expect(form.state.isValid).toBe(false)
29082908
expect(form.state.canSubmit).toBe(true)
29092909
})
2910+
2911+
it('should delete fields when resetting an array field to an empty array', () => {
2912+
const employees = [
2913+
{
2914+
firstName: 'Darcy',
2915+
},
2916+
] as const
2917+
2918+
const form = new FormApi({
2919+
defaultValues: {
2920+
employees,
2921+
},
2922+
})
2923+
form.mount()
2924+
2925+
form.clearValues('employees')
2926+
2927+
expect(form.getFieldValue('employees')).toEqual([])
2928+
expect(form.getFieldValue(`employees[0]`)).toBeUndefined()
2929+
expect(form.getFieldMeta(`employees[0]`)).toBeUndefined()
2930+
expect(form.state.values.employees).toStrictEqual([])
2931+
})
29102932
})

0 commit comments

Comments
 (0)