mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
🐛 should not print warning for not generating help and validateStatus automatically when help or validateStatus is specified
close #14911
This commit is contained in:
parent
9559a12be9
commit
924e8e4b83
@ -66,8 +66,10 @@ export default class FormItem extends React.Component<FormItemProps, any> {
|
||||
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.',
|
||||
);
|
||||
|
@ -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>
|
||||
<Form.Item label="Account">
|
||||
{form.getFieldDecorator('account')(<input />)}
|
||||
{form.getFieldDecorator('account')(<input />)}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
);
|
||||
});
|
||||
|
||||
mount(<Form1 />);
|
||||
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>
|
||||
<Form.Item label="Account" help="custom help information">
|
||||
{form.getFieldDecorator('account')(<input />)}
|
||||
{form.getFieldDecorator('account')(<input />)}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
);
|
||||
});
|
||||
|
||||
mount(<Form1 />);
|
||||
expect(errorSpy).not.toHaveBeenCalled();
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user