Open ekingan opened 5 years ago
I have noticed the same in my forms using react-select.
This also only occurs when I transform the data after submitting and the backend returns an error. It doesn't matter if I transform the data in my onSubmit function or in a redux action. I still experience the same issue. If no transformation of data happens, there are no issues.
A console.log while submitting shows that my transformed values from my onSubmit gets passed down to the form again, and Formik sets those as the values instead of the original form values.
I feel like I am missing something since that happens.
Would also love to get some help on this. Been experiencing it for a while. Thanks!
@jarleriksen How did you resolve the issue? Did you convert the data on the server side or on the client side when the data gets returned to the form after submit?
@ekingan I haven't solved it yet. I've just been lucky that the request has never failed so far. But I would really like to solve it.
I just submitted an issue with Stripe
here for it might be related.
stripe/stripe-react-js#109
I believe when you press the submit button the form is re-rendered by some state variable within formik. Thus wiping your stored data.
Any help would be appreciated.
When submitting form fails, select dropdown does not maintain the proper value
I am using
React
,Formik
, andreact-select
. I am having trouble with a dropdown select field for country.Before I submit the form, I can see that the form has both a value and a label:
returns this
{value: "United States", label: "United States"}
After I submit the form and the post request responds with a failure (this is a desired failure for test purposes), all other forms retain their values with the exception of this dropdown. Now the same
console.log
returns only"United States"
For the dropdown to work, it needs to be provided an object in the format mentioned before
{value: "United States", label: "United States"}
or the dropdown appears blank. Obviously, I could instrument a work around and set the field value again usingsetFieldValue
, but I feel I am missing something in regards to the Formik lifecycle. One other important thing to mention is that before I send the post request I am modifying the data I send to the server and only sending the value of the country, not the entire value and label object, like this:Here is my post request:
Can anyone help figure out why the values of this field change after submit? Thanks!