Skip to content

Provide option to call change from outside/initialChange #275

@rvsia

Description

@rvsia

Scope: 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️⃣ ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions