Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialValues not working for dynamic data #1487

Open
ag13 opened this issue Sep 29, 2024 · 1 comment
Open

initialValues not working for dynamic data #1487

ag13 opened this issue Sep 29, 2024 · 1 comment

Comments

@ag13
Copy link

ag13 commented Sep 29, 2024

Scope: FormRenderer

Description: When initialValues is set to a static object like initialValues={{type: {label: "test", value: "1"}}}, it correctly initialises the value but when the same data comes in from an API call and is passed to initialValues prop it fails to initialise it correctly. The useFormApi is correctly getting the initialValues but it does not pass through to the fields.

Schema: fields: [ { component: 'radio', name: 'type', label: 'Type', actions: { options: ['getTypes'], }, }]

Renderer code

<FormRenderer componentMapper={componentMapper} FormTemplate={FormTemplate} actionMapper={actionMapper} schema={schema} onSubmit={asyncSubmit} onCancel={() => console.log('Cancelling')} onReset={() => console.log('Resetting')} initialValues={dataFromApi} //{type: {label: "test", value: "1"}} subscription={{ values: true, initialValues: true }} />

@Hyperkid123
Copy link
Member

@ag13 , hi can you provide an example in codesandbox? Changing initial values should work unless some fields were already changed, then the form will not reset the values it has to be done via the form API.

Here is a minimal example that changes the values: https://codesandbox.io/p/sandbox/vwch9x. After 1,5 s the value of the text field is changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants