Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant Design error: "Form.create() getFieldDecorator is not a function"

"antd": "^1.11.1",
"react": "^15.1.0",
"react-dom": "^15.1.0",

Error: Uncaught TypeError: getFieldDecorator is not a function

ant design demo: https://ant.design/components/form/

import React, {Component} from 'react';
import { Form, Icon, Input, Button } from 'antd';
const FormItem = Form.Item;

const HorizontalLoginForm = Form.create()(React.createClass({
  handleSubmit(e) {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
      }
    });
  },
  render() {
    const { getFieldDecorator } = this.props.form;
    return (
      <Form inline onSubmit={this.handleSubmit}>
        <FormItem>
          {getFieldDecorator('userName', {
            rules: [{ required: true, message: 'Please input your username!' }],
          })(
            <Input addonBefore={<Icon type="user" />} placeholder="Username" />
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('password', {
            rules: [{ required: true, message: 'Please input your Password!' }],
          })(
            <Input addonBefore={<Icon type="lock" />} type="password" placeholder="Password" />
          )}
        </FormItem>
        <FormItem>
          <Button type="primary" htmlType="submit">Log in</Button>
        </FormItem>
      </Form>
    );
  },
}));

export default HorizontalLoginForm;
like image 266
Yanan Wang Avatar asked Nov 20 '16 01:11

Yanan Wang


1 Answers

.getFieldDecorator() is introduced in [email protected]

You can find 1.x docs here http://1x.ant.design

like image 196
yesmeck Avatar answered Oct 15 '22 09:10

yesmeck