Discussion for a new feature - Accept native FormData #83
Open
Description
Context
Although it is not a web standard, it is common to use dot/bracket syntax to represent arrays and nested objects.
Some frameworks like Adonis and Express (with body parser) handle that automatically.
However, with Remix or RSC actions, that expose a native FormData object without any extra preprocessing, handling arrays and objects is not so straightforward and we would need to manually parse the FormData (or use some lib) before forwarding it to the vine validator.
async function myAction(formData: FormData) {
const form = preprocessFormData(formData)
const data = await vine.validate({ data: form, schema })
}
Solutions
Since it's a common case for frameworks that use the native FormData, it would be nice if vine could handle that without extra libs / developer work. I'm not sure what would be the best way to do it though, here are some ideas:
- The
data
option accepts FormData objects:In this case the validate method would check if formData is instanceof FormData and then apply the preprocessing before matching the schema.await vine.validate({ data: formData, schema })
- External method
Include a new method or function (name is up to discussion) to preprocess the formData before calling validate.
await vine.validate({ data: vine.process(formData), schema })
Metadata
Assignees
Labels
No labels