remix-params-helper icon indicating copy to clipboard operation
remix-params-helper copied to clipboard

Is there a way to pass FormData that's already consumed?

Open nobleach opened this issue 5 months ago • 1 comments

Is there a way to pass FormData that's already consumed?

I realize I could just use straight Zod at that point but I really like the API of this project. Instead of passing my Request object, it'd be cool to do

const formData = await request.formData();
// Pull some value that helps me decide which validation schema to use
const employeeType = formData.get('employeeType');

  const result = await getFormData(formData, getValidationSchema(employeeType));

  if (!result.success) {
    return json(result.errors, { status: 400 });
  }

I didn't know if there was a technical reason that the entire request object needed to be passed. As we know the body cannot be consumed twice so there's no potential for getting data from it to assist in making validation decisions.

Thoughts?

nobleach avatar Sep 22 '24 12:09 nobleach