Skip to content

Commit 14a178a

Browse files
committed
Re-introduce reset()
1 parent 4656813 commit 14a178a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class MyForm extends React.Component {
253253
If you want to force re-validate all fields, use `validateFields()`.
254254

255255
- `validateForm(): Promise<Field[]>` =>
256-
Other name for `validateFieldsWithoutFeedback()`, typically called before to submit the `form`.
256+
Same as `validateFieldsWithoutFeedback()` without arguments, typically called before to submit the `form`.
257257
Might be removed in the future?
258258

259259
- `isValid(): boolean` => should be called after `validateFields()`, `validateFieldsWithoutFeedback()` or `validateForm()`, tells if the fields are valid

packages/react-form-with-constraints/src/FormWithConstraints.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,3 +1725,16 @@ describe('resetFields()', () => {
17251725
wrapper.unmount();
17261726
});
17271727
});
1728+
1729+
test('reset()', async () => {
1730+
const wrapper = mount(<SignUp />);
1731+
const signUp = wrapper.instance() as SignUp;
1732+
const resetFieldsSpy = jest.spyOn(signUp.form!, 'resetFields');
1733+
1734+
await signUp.form!.reset();
1735+
1736+
expect(resetFieldsSpy).toHaveBeenCalledTimes(1);
1737+
expect(resetFieldsSpy.mock.calls).toEqual([[]]);
1738+
1739+
wrapper.unmount();
1740+
});

packages/react-form-with-constraints/src/FormWithConstraints.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class FormWithConstraints
6666
return this._validateFields(/* forceValidateFields */ true, ...inputsOrNames);
6767
}
6868

69+
// TODO To be removed in the future?
6970
validateForm() {
7071
return this.validateFieldsWithoutFeedback();
7172
}
@@ -193,6 +194,11 @@ export class FormWithConstraints
193194
return this.fieldsStore.hasFeedbacks();
194195
}
195196

197+
// TODO To be removed in the future?
198+
reset() {
199+
return this.resetFields();
200+
}
201+
196202
async resetFields(...inputsOrNames: Array<InputElement | string>) {
197203
const fields = new Array<Readonly<Field>>();
198204

0 commit comments

Comments
 (0)