Skip to content

Commit

Permalink
fixed form validation not running
Browse files Browse the repository at this point in the history
  • Loading branch information
aadito123 committed Oct 31, 2023
1 parent b16e0f9 commit 52b6245
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/form-core/src/FormApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class FormApi<TFormData, ValidatorType> {
this.store.setState((prev) => ({
...prev,
isValidating: true,
isFormValidating: true,
formValidationCount: prev.formValidationCount + 1,
}))

Expand All @@ -274,6 +275,7 @@ export class FormApi<TFormData, ValidatorType> {
this.store.setState((prev) => ({
...prev,
isValidating: false,
isFormValidating: false,
formError: error ? 'Invalid Form Values' : false,
}))

Expand Down Expand Up @@ -400,14 +402,14 @@ export class FormApi<TFormData, ValidatorType> {
}))
}

this.validateForm()

this.store.setState((prev) => {
return {
...prev,
values: setBy(prev.values, field, updater),
}
})

this.validateForm()
})
}

Expand Down
4 changes: 3 additions & 1 deletion packages/form-core/src/tests/FormApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ describe('form api', () => {
expect(form.state.canSubmit).toBe(false)

field.handleChange('ayo')
await sleep(11)
await sleep(1)
expect(form.state.isFormValidating).toBe(true)
await sleep(9)

expect(form.state.isFormValidating).toBe(false)
expect(form.state.isFormValid).toBe(true)
Expand Down

0 comments on commit 52b6245

Please sign in to comment.