forge42dev / remix-hook-form

Open source wrapper for react-hook-form aimed at Remix.run
MIT License
330 stars 27 forks source link

Allow `encType: "application/json"` from `submitConfig` #93

Closed edbella closed 2 months ago

edbella commented 4 months ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch remix-hook-form@4.3.1 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/remix-hook-form/dist/index.js b/node_modules/remix-hook-form/dist/index.js
index 6fd94e4..cd0637a 100644
--- a/node_modules/remix-hook-form/dist/index.js
+++ b/node_modules/remix-hook-form/dist/index.js
@@ -130,8 +130,9 @@ var useRemixForm = ({
   const onSubmit = useMemo(
     () => (data2) => {
       setIsSubmittedSuccessfully(true);
-      const formData = createFormData(
-        { ...data2, ...submitData },
+      const submitPayload = { ...data2, ...submitData };
+      const formData = submitConfig?.encType === 'application/json' ? submitPayload : createFormData(
+        submitPayload,
         stringifyAllValues
       );
       submit(formData, {

I noticed that when I set the encType value to application/json in the submitConfig, the data being sent still remained as FormData.

This issue body was partially generated by patch-package.

CestDiego commented 3 months ago

Yes please! This is super important to me as I'm trying to also use the useFieldArray from react-hook-form.

nelsliu9121 commented 2 months ago

I believe you should make this into an PR.