mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-06 04:19:43 +00:00
fix: FormApi's deleteField method now updates the store
* Add basic tests for arrays * Ran prettier * Ran prettier * Add new test for bug * Fix bug regarding preserved values even if field is umounted * Run prettier * Update store subscription when removingFields * Fix delete field * Fix delete field * chore: fix linting --------- Co-authored-by: Corbin Crutchley <git@crutchcorn.dev>
This commit is contained in:
@@ -551,11 +551,12 @@ export class FormApi<TFormData, ValidatorType> {
|
||||
}
|
||||
|
||||
deleteField = <TField extends DeepKeys<TFormData>>(field: TField) => {
|
||||
const newState = { ...this.state }
|
||||
delete newState.values[field as keyof TFormData]
|
||||
delete newState.fieldMeta[field]
|
||||
|
||||
this.store.setState((_) => newState)
|
||||
this.store.setState((prev) => {
|
||||
const newState = { ...prev }
|
||||
delete newState.values[field as keyof TFormData]
|
||||
delete newState.fieldMeta[field]
|
||||
return newState
|
||||
})
|
||||
}
|
||||
|
||||
pushFieldValue = <TField extends DeepKeys<TFormData>>(
|
||||
|
||||
@@ -611,5 +611,7 @@ describe('field api', () => {
|
||||
// Field should have been removed from the form as well
|
||||
expect(form.state.values.name).toBeUndefined()
|
||||
expect(form.state.fieldMeta.name).toBeUndefined()
|
||||
expect(form.store.state.values.name).toBeUndefined()
|
||||
expect(form.store.state.fieldMeta.name).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user