Skip to content

Discussion for a new feature - Accept native FormData #83

Open
@okalil

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:

  1. The data option accepts FormData objects:
       await vine.validate({ data: formData, schema })
    In this case the validate method would check if formData is instanceof FormData and then apply the preprocessing before matching the schema.
  2. External method
      await vine.validate({ data: vine.process(formData), schema })
    Include a new method or function (name is up to discussion) to preprocess the formData before calling validate.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions