Skip to content

Commit

Permalink
fix: return validation result on form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
balavishnuvj committed Nov 11, 2020
1 parent 56533e2 commit b4b0ad5
Show file tree
Hide file tree
Showing 3 changed files with 1,787 additions and 1,687 deletions.
14 changes: 13 additions & 1 deletion src/__tests__/forms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,23 @@ describe('Unit Test cases for use-form hook', () => {
expect(result.current[0].name.value).toBe(text);
expect(result.current[0].name.isValid).toBe(false);
expect(result.current[1].isValid).toBe(false);
let returnedValue;
await act(async () => {
await result.current[1].validate();
returnedValue = await result.current[1].validate();
});
expect(result.current[0].name.isValid).toBe(true);
expect(result.current[1].isValid).toBe(true);
expect(returnedValue).toMatchInlineSnapshot(`
Array [
true,
Object {
"name": Object {
"errorMsg": "",
"isValid": true,
},
},
]
`);
});
});
describe('Cases of use-form on demand config change', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/use-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ export default function useNewForm(fieldConfig) {
);

const validateForm = useCallback(async () => {
const [, errors] = await getFormErrors(
const [isValid, errors] = await getFormErrors(
fieldConfigRef.current,
formValuesAsRef.current,
);
setFormErrors(errors);
return [isValid, errors];
}, []);

const updateFieldConfig = useCallback(
Expand Down
Loading

0 comments on commit b4b0ad5

Please sign in to comment.