how to get field value on change for FormItem in antd

前端 未结 3 1782
无人共我
无人共我 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 16:55

    I realize this is super late, but I think this might be what OP was looking for:

    https://github.com/react-component/form/blob/3b9959b57ab30b41d8890ff30c79a7e7c383cad3/examples/server-validate.js#L74-L79

    To set fields on a form dynamically, e.g. in a child via a callback, you could use

        this.props.form.setFields({
          user: {
            value: values.user,
            errors: [new Error('forbid ha')],
          },
        }); 
    

    in a parent defined handleSelect method you called from the child on a selected value. you can alternatively use setFieldsValue if you dont want to pass an error field

提交回复
热议问题