Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 fix #9521 isValidating property stuck to true #9523

Merged
merged 1 commit into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/__tests__/useFormState.test.tsx
Expand Up @@ -118,6 +118,57 @@ describe('useFormState', () => {
expect(count).toEqual(1);
});

it('should update isValidating correctly', async () => {
function Child() {
const { isDirty, isValid, isValidating } = useFormState();
const enabled = !isValidating && isDirty && isValid;

return (
<button disabled={!enabled} type="submit">
Submit
</button>
);
}

function App() {
const formFunctions = useForm({
mode: 'onChange',
});
const { register } = formFunctions;

return (
<FormProvider {...formFunctions}>
<form>
<input {...register('value', { required: true })} />
<Child />
</form>
</FormProvider>
);
}

render(<App />);

fireEvent.change(screen.getByRole('textbox'), {
target: {
value: '1',
},
});

await waitFor(() => {
expect(screen.getByRole('button')).not.toBeDisabled();
});

fireEvent.change(screen.getByRole('textbox'), {
target: {
value: '12',
},
});

await waitFor(() => {
expect(screen.getByRole('button')).not.toBeDisabled();
});
});

it('should update formState separately with useFormState', async () => {
let count = 0;
let testCount = 0;
Expand Down
1 change: 0 additions & 1 deletion src/logic/createFormControl.ts
Expand Up @@ -175,7 +175,6 @@ export function createFormControl<

const _updateIsValidating = (value: boolean) =>
_proxyFormState.isValidating &&
value !== _formState.isValidating &&
_subjects.state.next({
isValidating: value,
});
Expand Down