seasonedcc / remix-forms

The full-stack form library for Remix and React Router
https://remix-forms.seasoned.cc
MIT License
494 stars 25 forks source link

Hidden field value does not get submitted unless Field rendered #146

Open bitofbreeze opened 1 year ago

bitofbreeze commented 1 year ago

I was very confused why this was happening for a while based on the docs that show that declaring the hidden fields with values in the Form props is enough.

It turns out when you use a custom form, you must write an instance of Field for the hidden inputs too. You can see in my repro that submitting with line 60 commented gives no value in the action for "hidden", but uncommenting it does. I wonder if this is intended behavior, and if so, if the docs can be clarified.

I don't understand why we even declare the hidden field in the props if you still have to write the Field JSX for it.

darlantc commented 1 year ago

I agree with you, this is annoying specially because it is hard to catch the problem when those hidden fields holds required values to submit the form. It would be nice to have the hidden fields automatically pushed to the render tree for custom forms.

noels commented 4 days ago

I have also just run into this. Additionally, errors on hidden fields don't show as 'global' errors on the form. If I write a custom input like: https://remix-forms.seasoned.cc/examples/forms/custom-input I can display the errors, but I think it would be useful to just throw an exception if any hidden field fails validation so it is shown in the global errors. I think this is a better DX than wondering why your form failed to submit. I have tried on both main and the experimental branch, and the behaviour is the same.