-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion for a new feature - Accept native FormData #83
Comments
I was very surprised that vinejs doesn't (it seems) support this already. Vine's docs seem to indicate that it should be stupid simple to handle form data: Built for validating form data and JSON payloads Numbers and booleans are serialized as strings And yet when I try to simple run the following code:
I receive an error with messages:
|
Yeah.. For now I created a separate class to parse the body: const data = bodyParser.parse(formData) // handles nested fields with dot/bracket notation
const { email, password } = await vine.validate({ data, schema }) But it would be great if there was a built in function for that. |
Could we add a 1-liner like this somewhere? data = data instanceof FormData ? Object.fromEntries(data.entries()) : data; |
The issue will be nested data/array indexes. For example: How would <div>
<label for="email-1"> Email 1 </label>
<input type="email" id="email-1" name="users[0]['email']">
</div>
<div>
<label for="email-2"> Email 2 </label>
<input type="email" id="email-2" name="users[1]['email']">
</div> |
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.
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:
data
option accepts FormData objects:The text was updated successfully, but these errors were encountered: