Open jessicamann opened 5 years ago
That completely makes sense. One more common use case that can not be implemented now: if you want to show error icon in the header of the collapsed panel to show that there are some fields with errors inside it. But of course, you want to show this icon only if this field was touched, otherwise freshly opened form will be already filled with error icons. Currently there is no way to know whether a field was already touched when you close a panel (-> field dom destroyed -> field is unregistered -> field meta is lost)
Even more basic use case. If your form is split by multiple tabs/collapsible panels/modal windows/whatever that can be destroyed and recreated.
I am also getting the error removed from the form state, while submit error is being persisted.
@Mottoweb The way I solve this is just keep dummy registered all fields, all the time.
const Dummy = () => {
useField("fieldA")
useField("fieldB")
....
}
<Form ...>
<Dummy />
....
</Form>
Are you submitting a bug report or a feature request?
Bug report
What is the current behavior?
Field are unregistered, causing meta data (dirty/valid/etc) to be lost, when they are removed from the DOM. The meta data is regained once the field is brought back into the DOM.
See the code sandbox attached for how the Button cannot property stay enabled when the collapsible panel has been closed once a field value is adjusted.
Steps to reproduce:
What is the expected behavior?
Fields remain registered upon removal from the DOM, ensuring other subscribers access to it and the form's values and meta states.
Removing elements from the DOM when not in view can be to optimize view performance; it is not necessarily an intent to remove the field from the form.
Sandbox Link
https://codesandbox.io/s/expansion-panel-with-field-zusgx
What's your environment?
react-final-form: 6.3.0 final form: 4.18.5