how to get field value on change for FormItem in antd

前端 未结 3 1789
无人共我
无人共我 2021-02-13 16:48

I am having a hard time with antd\'s form. I have this select field in this form and I want to get the value from it onChange but somehow not getting it to work properly.

<
3条回答
  •  無奈伤痛
    2021-02-13 17:15

    Try this:

    
      {getFieldDecorator("qcategoryid", {
        rules: [{ required: true, message: "Please select Category!" }]
      })()}
    
    

    And on the handleCategoryChange function

    handleCategoryChange = (value, e) => {
      this.setState({
        categorySelected: value,
        categoryname: e.props.name
      });
    };
    

    Basically, changing the onChange from the getFieldDecorator helper to the Select, so it doesn't mess with antd's natural behavior, but gets the value and change on state

    I've based this answer on the code to the registration form on their website. Specifically, the handleWebsiteChange function

    https://ant.design/components/form/#components-form-demo-register

提交回复
热议问题