final-form / final-form/final-form
Include data in resulting object from form.getState()
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
### **feature request**
I've just discovered mutators. They are awesome!
I'm adding data to my fields with `final-form-set-field-data`. I also learned that I can initialise the data property when registering the fields. (https://github.com/final-form/final-form/issues/240#issuecomment-510536324)
Since **data** seems to be the decided property name for arbitrary field data it would be great to get the data property for all fields from `form.getState()`.
### Proposed solution
This feature would be simple to implement by piggy-backing on the existing reduce function in calcNextFormState()
https://github.com/final-form/final-form/blob/a2047e07d7a99e5730b54c413d2a06dd2743b4bb/src/FinalForm.js#L554
My user-land solution is to reduce over `getRegisteredFields` at submit, like this:
```
const data = form.getRegisteredFields().reduce(function(result, key) {
result[key] = form.getFieldState(key).data;
return result;
}, {});
```
I would really like form.getState() to output a data-object. I also think others would benefit from this.
I could make a PR if this is interesting.
Contributor guide
Assessment
This issue has not been assessed yet.