From 924e8e4b83886a42f8c0295d989e1e9275a656f5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 22 Feb 2019 14:01:03 +0800 Subject: [PATCH] :bug: should not print warning for not generating help and validateStatus automatically when help or validateStatus is specified close #14911 --- components/form/FormItem.tsx | 4 ++- components/form/__tests__/message.test.js | 39 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index e0e4a1ed83..8520a60687 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -66,8 +66,10 @@ export default class FormItem extends React.Component { helpShow = false; componentDidMount() { + const { children, help, validateStatus } = this.props; warning( - this.getControls(this.props.children, true).length <= 1, + this.getControls(children, true).length <= 1 || + (help !== undefined || validateStatus !== undefined), '`Form.Item` cannot generate `validateStatus` and `help` automatically, ' + 'while there are more than one `getFieldDecorator` in it.', ); diff --git a/components/form/__tests__/message.test.js b/components/form/__tests__/message.test.js index a48167a5c8..98b61ace5a 100644 --- a/components/form/__tests__/message.test.js +++ b/components/form/__tests__/message.test.js @@ -87,4 +87,43 @@ describe('Form', () => { expect(wrapper.render()).toMatchSnapshot(); }); + + it('should print warning for not generating help and validateStatus automatically', () => { + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const Form1 = Form.create()(({ form }) => { + return ( +
+ + {form.getFieldDecorator('account')()} + {form.getFieldDecorator('account')()} + +
+ ); + }); + + mount(); + expect(errorSpy).toBeCalledWith( + 'Warning: `Form.Item` cannot generate `validateStatus` and `help` automatically, while there are more than one `getFieldDecorator` in it.', + ); + errorSpy.mockRestore(); + }); + + // https://github.com/ant-design/ant-design/issues/14911 + it('should not print warning for not generating help and validateStatus automatically when help or validateStatus is specified', () => { + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const Form1 = Form.create()(({ form }) => { + return ( +
+ + {form.getFieldDecorator('account')()} + {form.getFieldDecorator('account')()} + +
+ ); + }); + + mount(); + expect(errorSpy).not.toHaveBeenCalled(); + errorSpy.mockRestore(); + }); });