Provide option to call change from outside/initialChange
See original GitHub issueScope: FormRenderer
Description
In Sources UI I have this following flow:
[ FORM ]
> submit 📨 > 💥 ☠️ > [ ERROR_PAGE ]
> retry button ♻️ > [ FORM ]
The form has set initialValues. In the submit action, form values and initial values are compared and only modified values are sent to an API.
I need to re-set the values when restarting the form after an error occurs (formValues from the first attempt set in the second attempt). However, I cannot use the initial values, because I am using them to compare new values with initials. (So in the second attempt: formValues = initialValues = no values 😭 )
I propose two ways how to solve this riddle:
1st ) Provide a way how to call onChange
outside the form
2nd and maybe preferred ) Provide something like initialChange, which will be called only once and will call change
event with provided values after the form renderer is mount
Schema
<FormRenderer
schema={schema}
formFieldsMapper={formFieldsMapper}
layoutMapper={layoutMapper}
onSubmit={console.log}
initialValues={{
name: 'Mike Johnson'
}}
initialChange={{
name: 'John Smith'
}}
/>
=> modified fields: name
What do you think, @Hyperkid123 👾 1️⃣ 2️⃣ 3️⃣ ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
The thing is this behavior is very specific. I did play with the idea of exposing the formApi from the get-go but ultimately decided against it and I will be until someone finds some use-case where there is no other way 😄. To be clear the above-proposed solutions are not that simple and clean to implement inside the renderer. I tried.
It is possible to compare the first initialValues, and second ones in the submit action but I am just trying to find some clean and simple solution. Alright, I will do it other way, thanks for discussing this! This can be closed now.