Search code examples
reactjsantdreact-propsant-design-proreact-state

Set form text field values after the form submission with ant design in react


I need to change the form text field value after submitting it. I used https://ant.design/components/form/ ant design to create the form.

I have tried the following code inside the form onSubmit method.

this.props.form.setFieldsValue({ count: pasId});

Here count is the getFieldDecorator's id. But the count field value doesn't change to value of pasId variable when I checked as follows.

console.log(values.count);

So where I could get wrong and how to set the form field value after the form values get submitted to the db?


Solution

  • Looks like you need to be using fieldDecorators, as I can see in the source code for the example for setFieldsValue.

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

    https://github.com/ant-design/ant-design/blob/master/components/form/demo/coordinated.md