feat(core): add setErrors
and setFieldError
#24
Merged
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.
π Linked issue
Resolves #17
β Type of change
π Description
Add
setErrors
andsetFieldError
Currently, in Vorms, it is not possible to set errors without performing validation. This limitation becomes inconvenient when we encounter errors in API responses that do not adhere to the predefined validation rules.
To address this issue, we have introduced two new methods,
setError
andsetFieldError
, in this PR. These methods can be used within thehandleSubmit
function to provide error feedback to the user after performing asynchronous validation. (ex: API response validation errors occur).More flexible error message type
According to Can Vorms provide pass/fail results for each validation specification?Β #17, there are cases where we need to provide a list of error messages for a field, displaying all the reasons for failure to the user, instead of just a single error message string.
In the current version, we can still use an array of strings to return a list of error messages, and it works, but dealing with type errors can be frustrating.
With this PR, we introduce a solution that allows us to return an error message, which can be either a string or an array of strings, without encountering type errors. This improvement ensures a smoother experience by providing flexibility in handling error messages, accommodating both single and multiple failure reasons.
π Checklist