Skip to content
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

<Form> + File[] field is not mapped to FormData correctly #113

Closed
OkayX6 opened this issue Oct 2, 2024 · 1 comment
Closed

<Form> + File[] field is not mapped to FormData correctly #113

OkayX6 opened this issue Oct 2, 2024 · 1 comment

Comments

@OkayX6
Copy link

OkayX6 commented Oct 2, 2024

Hi,

Version: 4.3.0 but also 5.1.0

Symptom

When using the useRemixForm<>() naively

Using this schema:

const dataRequestSchema = z.object({
  // A pure HTML Input with multiple files would have type 'FileList'
  // But our usage of react-dropzone + react-hook-form controller sends an array of File
  files: z.array(z.instanceof(File)),
  comments: z.string().nullable(),
})

The files param is not mapped correctly like it should in the FormData (Chrome request window) - it is serialized as an array of strings:

image

--
I had to define a custom submitHandler

const form = useRemixForm<DataRequest>({
    resolver: zodResolver(dataRequestSchema),
    submitHandlers: {
      onValid: (data) => {
        const formData = new FormData()
        // Send a File[] called 'files'
        for (const file of data.files) {
          formData.append('files', file)
        }
       ...

Not sure if the fix is complex =)

@AlemTuzlak
Copy link
Contributor

should work now with 5.1.1, please re-open if not the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants