final-form / final-form/react-final-form

Extend FieldRenderProps meta object with information about whether a field has been added since the last (attempted) submit

Open
#322 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

### Are you submitting a **bug report** or a **feature request**?

Feature request

This feature request stems from [this](https://stackoverflow.com/questions/52002850/determine-when-a-field-using-final-form-arrays-is-newly-inserted) StackOverflow question. Since posting the question, I came to realize that this is actually a more general behavior that I believe should be implemented in this library.

### What is the current behavior?

[`FieldRenderProps`](https://github.com/final-form/react-final-form#fieldrenderprops) `meta` property contains a `dirtySinceLastSubmit` flag, which can be useful to carry out validation logic. Because fields can be dynamically registered (i.e. via final-form-arrays), it would be useful to have a new flag named `newSinceLastSubmit` (or something along the lines), to convey when a field has been dynamically registered since the last submit.

### What is the expected behavior?

Have a new property `FieldRenderProps.meta.newSinceLastSubmit` which is set to true when a field has been registered anew since the last submit/validation event. This would be useful for instance to skip validation on dynamically added fields.

For example, if fields being rendered via final-form-arrays have a validator that imposes that they are required (their value is truthy) and shows an error message otherwise, you might want to implement a behavior that doesn't show the error message if they have just been added to the form, and only show the error message on the next validation/attempted submit of the form. This is currently not possible with the contextual information provided to the validator.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.