bpmn-io / form-js

View and visually edit JSON-based forms.
https://bpmn.io/toolkit/form-js/
Other
406 stars 104 forks source link

Make it possible to change form data after first render #39

Open vsgoulart opened 3 years ago

vsgoulart commented 3 years ago

Is your feature request related to a problem? Please describe

On Zeebe Tasklist if we try to complete a Task that was already completed we receive the updated Task and update the values on the form. To do that we need a way to update the values after the first render.

Describe the solution you'd like

const form = createForm({
// ...
});

form.setData(newData);

// or

form.setProperty('data', newData)

Additional context

Currently I'm using form.setState({ data }) for that, but I assume that it's not public API and not very wise to use it on long term

nikku commented 3 years ago

What is the expectation regarding the dirty state in such scenario? Is the dirty state reset? Is the dirty state updated, i.e. does it act like a bulk edit?

vsgoulart commented 3 years ago

I would assume we reset the dirty state, even though that's not important for us because on this specific case we'll set the form to readOnly mode after changing the value.

On other libraries to manage forms that I have experience using, like react-final-form, they reset the form meta state but allow an option to keep dirty on reinitialize

philippfromme commented 3 years ago

What is the dirty state of a form (viewer)? Are you referring to the errors being displayed?

vsgoulart commented 3 years ago

What is the dirty state of a form (viewer)? Are you referring to the errors being displayed?

The dirty state is a flag to signal if the current values of the form is different than the values the form was initialized with. At least it is with other form libraries I have used like react-final-form and formik.