rekit / antd-form-builder

Dynamic meta driven React forms based on antd.

Home Page:https://rekit.github.io/antd-form-builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InitialValues not working anymore

jonathanroze opened this issue · comments

HI,

I just switch from Antd@3 to Antd@4 and i upgrade your module.

I change my code to fit new specs but when I provide initialValues, there are not more informations in my fields.

              <Form onSubmit={this.handleSubmit}>
                <FormBuilder form={this.form} meta={{...formLayout, initialValues: resource, disabled}} />
              </Form>

That my code, and resource object is in my component state, it's async loading (fetch from api)

I can't reproduce it. Could you create an example on codesandbox.io to reproduce?

In your case you modified initial value after form's rendering. This behavior has been changed for the antd's form API: https://ant.design/components/form/v3 .

In v3, modifying the initialValue of un-operated field will update the field value synchronously, which is a bug. However, since it has been used as a feature for a long time, we have not fixed it. In v4, the bug has been fixed. initialValues only takes effect when initializing and resetting the form.

The antd-form-builder just inherits the same behavior. So, to change field value after the initial rendering, you should use this.form.setFieldValue(..).

Ok perfect, thanks :)