简体   繁体   English

未被捕获的TypeError:无法读取未定义的属性“ form”

[英]Uncaught TypeError: Cannot read property 'form' of undefined

Am pretty new to JavaScript and React but have been playing around with a antd a UI Component library creating a form with validation but ran into some troubles. 对JavaScript和React来说是一个很新的事物,但是一直在使用一个古老的UI组件库来创建带有验证的表单,但遇到了一些麻烦。

Following their API/Documentation here I created a Form which should contain the props when using From.create however I get a Uncaught TypeError: Cannot read property 'form' of undefined1 when doing so in the checkConfirm function const form = this.props.form; 按照这里的API /文档我创建了一个Form,使用From.create时应包含道具,但是却收到Uncaught TypeError: Cannot read property 'form' of undefined1在checkConfirm函数const form = this.props.form;这样做时, Uncaught TypeError: Cannot read property 'form' of undefined1 const form = this.props.form; line. 线。

  class CustomizedForm extends React.Component {
  constructor(...args) {
    super(...args);
  }
  handleSubmit() {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
      }
    })
  }
  checkConfirm(rule, value, callback) {
    console.log(value.length);
    const form = this.props.form;
    if (value.length == 11) {
      form.validateFields(['confirm'], { force: true });
    };
    callback();
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 }
    };
    return (
      <div>
        <Form inline style={{ marginTop: 10, marginBottom: 10 }} onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayout}
            hasFeedback
            >
            {getFieldDecorator('password', {
              rules: [{
                required: true, message: 'Please input your password!',
              }, {
                validator: this.checkConfirm,
              }],
            })(
              <Input placeholder="password" />
              )}
          </FormItem>
          <FormItem hasFeedback>

          </FormItem>
          <FormItem          >
            <Input style={{ width: '200px' }} size="default" placeholder="Shelf Place"></Input>
          </FormItem>
          <FormItem>
            <ProcessSelect />
          </FormItem>
          <FormItem>
            <ZoneSelect />
          </FormItem>
          <FormItem>
            <ZalosRangePicker />
          </FormItem>
          <FormItem>
            <ButtonGroup size="default">
              <Button size="default" icon="search" />
              <Button size="default" icon="close" />
            </ButtonGroup>
          </FormItem>
        </Form>
      </div>
    )
  }
}
CustomizedForm = Form.create({})(CustomizedForm);

I found some mistakes here, 我在这里发现了一些错误,

. Reason of error, 错误原因,

You need to bind this to function like, 您需要将此绑定到类似的功能,

 constructor(...args) {
    super(...args);
this.checkConfirm  = this.checkConfirm.bind(this)
  }

Function Defination 功能定义

checkConfirm(rule, value, callback) {
    console.log(value.length);
    const form = this.props.form;
    if (value.length == 11) {
      form.validateFields(['confirm'], { force: true });
    };
    callback();
  }

You are not passing any arrangements to function. 您没有通过任何安排以发挥作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery验证未捕获的TypeError无法读取未定义的属性“ form” - jQuery validate Uncaught TypeError Cannot read property 'form' of undefined 未捕获的类型错误:无法读取表单提交上未定义的属性“preventDefault” - Uncaught TypeError: Cannot read property 'preventDefault' of undefined on Form Submit 未捕获的TypeError:提交表单时无法读取未定义的属性&#39;element&#39; - Uncaught TypeError: Cannot read property 'element' of undefined when submitting form 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined 未捕获的TypeError:无法读取未定义的属性“数量” - Uncaught TypeError: Cannot read property 'quantity' of undefined 未捕获的TypeError:无法读取未定义的属性&#39;fromJSON&#39; - Uncaught TypeError: Cannot read property 'fromJSON' of undefined 未捕获的TypeError:无法读取未定义的属性“ timing” - Uncaught TypeError: Cannot read property 'timing' of undefined 未捕获的TypeError:无法读取未定义的属性&#39;formatter&#39; - Uncaught TypeError: Cannot read property 'formatter' of undefined Uncaught TypeError:无法读取未定义的属性“ stopVideo” - Uncaught TypeError: Cannot read property 'stopVideo' of undefined 未捕获的类型错误:无法读取未定义的属性“setCrossOrigin” - Uncaught TypeError: Cannot read property 'setCrossOrigin' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM