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.
This PR introduces new primitives:
safeParseFormData(schema, formData, config)
- Parses FormData input based on a schema.parseFormData(schema, formData, config)
- Similar to safeParseFormData but throws aFormError
in case of errors.decodeFormData(schema, formData)
- Decodes FormData without input validation.FormError
- Similar toValiError
, but contains flattened error messages for forms.isFormError
- A type guard to check if an error is aFormError
, similar toValiError
.Currently, I use a similar implementation in userland. However, since it heavily depends on valibot internals, I believe it is better to include it in the core package. These primitives are simple and align with the modular approach of the valibot library. This PR provides an alternative solution to the suggestions in #539 and #544. Please let me know your thoughts. I can add tests and documentation if the overall approach is approved.
Usage example:
For the following FormData:
Using the following schema:
Will output the following result: