Added formState.setFields
method to be able to update multiple fields at once
#91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all, thank you very much for this great package! It's an absolute breeze to work with!
One thing I've been missing is the ability to set the values of multiple fields at once. One example for this is when the data is loaded from the server. Currently one must set each field individually in a loop and then all those fields are also marked as
touched
which is not the case then.So there was a need to be able to set the values of fields in the state but also manage their
touched
andvalidity
state and while we're at it we could also seterrors
.Just setting values is simple:
But to be able to change the
touched
orvalidity
state or seterrors
a secondoptions
argument can be provided:Actually setting the
validity
of a field tofalse
when also providing an error for it is redundant so I took the liberty of marking fields for which errors are provided as invalid if and only if novalidity
option is passed.The same goes for setting the
validity
of a field totrue
. If a field is valid then you probably don't want to show an error so those are cleared if and only if no errors option is passed.I did my best to make this PR as complete as possible:
index.d.ts
file. (Please check it because I'm no TypeScript expert!)README.md
.Hope you appreciate it!
Kind regards,
Johan