airjp73 / rvf

Easy form validation and state management for React and Remix
https://rvf-js.io
MIT License
840 stars 66 forks source link

[Bug]: `useIsSubmitting()` prevents data from being sent to the server #287

Closed meoyawn closed 1 year ago

meoyawn commented 1 year ago

Which packages are impacted?

What version of these packages are you using?

Please provide a link to a minimal reproduction of the issue.

https://github.com/meoyawn/remix-validated-form-use-is-submitting

Steps to Reproduce the Bug or Issue

  1. Enter a valid url in the input
  2. Submit form
  3. Observe text "Required" (observe empty FormData in the Chrome Network tab)

Expected behavior

Submitting should render "Success". If you replace useIsSubmitting() call with false, you'll see it

Screenshots or Videos

image

You can see that formData is not passed to the server:

image

Platform

Additional context

useIsSubmitting() triggers React render, which replaces the form or something. Old <input /> gets removed from the DOM, making new FormData(form) lose all the fields that get rerendered by useIsSubmitting().

Sorry I couldn't get Remix to work with Codesandbox

airjp73 commented 1 year ago

Hi!

This is happening because you're disabling the input when isSubmitting === true. A disabled input is never included in the FormData. To fix, you could use readOnly instead of disabled.

That said, this will likely be fixed when I implement a fix for #117.

meoyawn commented 1 year ago

Hey, no rush, I replaced remix-validated-form with react-hook-form

meoyawn commented 1 year ago

and thanks! TIL that Tailwind also has a read-only: variant https://tailwindcss.com/docs/hover-focus-and-other-states#read-only