form
form copied to clipboard
validateFields throws an Error if no callback is provided
In the documentation of Ant's Form, there is an example where validateFields
is being called without any argument (https://ant.design/components/form/#components-form-demo-horizontal-login)
In this sandbox https://codesandbox.io/s/2wn69y7mqp when you open a console, you can see it's throwing an error because after recent changes in rc-form, callback
is being called even though it was not provided.
However when using validateFieldsAndScroll
it works fine, because callback
is only being called when it exists (here is the check https://github.com/react-component/form/blob/bdbd7b03e88b7d76ad58d39d978e5bce0c7abdf8/src/createDOMForm.js#L93)
I suppose there are 2 solutions:
- Make callback optional
- add a check
typeof callback === 'function'
also for thevalidateFields
- adjust documentation to make it clear that
callback
is optional
- Make callback required.
- unify behaviour of
validateFields
&validateFieldsAndScroll
. One throws and one works fine. Both should either print a warning or throw or check or whatever. - fix Ant's documentation and examples (eg. https://github.com/ant-design/ant-design/blob/65eb713fe897f65bbf187e215c664e5f9b468252/components/form/demo/register.md)
- fix Ant's TS types that allow calling
validateFields
andvalidateFieldsAndScroll
with no argument (https://github.com/ant-design/ant-design/blob/65eb713fe897f65bbf187e215c664e5f9b468252/components/form/Form.tsx) - fix Ant's tests (https://github.com/ant-design/ant-design/blob/65eb713fe897f65bbf187e215c664e5f9b468252/components/form/tests/message.test.js#L30)
I know this is not an Ant repo, so please let me know what is the desired solution and I can create a new ticket in Ant repository