final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.38k stars 480 forks source link

useField always returns checked to 'false' for radio type field with parse function #772

Open AdrienAgnel opened 4 years ago

AdrienAgnel commented 4 years ago

Hey, thanks for RFF :) I am having some troubles with a radio input:

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

I am using a parsed input field of type 'radio', managed trough useField. It appears the value stored in the form's state has well been parsed with my parse function. But then, when clicking on the button, the checked input prop return by useField is always false.

It seems useField is comparing the parsed value stored in the form state to the value of the radio but without parsing it first, see : https://github.com/final-form/react-final-form/blob/f3c1aea93b520c0620f1b8090f5966e0da94a798/src/useField.js#L221

I was wondering if this is deliberate ?

What is the expected behavior?

I would expect the value to be parsed in order to determine the checked value

Sandbox Link

Here is the sandbox : https://codesandbox.io/s/fervent-wright-20ngr

I would expect that clicking on "half" or "full" checks the related radio input (the example is not very usefull, but in my real case, the value of the form has to be parsed before being sent to my api and I have a "default" radio button which should be parsed to empty string '')

What's your environment?

justincy commented 4 years ago

This bug isn't specific to parsed inputs. You'll see the same behavior if you comment out the parse function, as shown in this sandbox: https://codesandbox.io/s/lucid-lehmann-pmeob

justincy commented 4 years ago

I fixed my problem by adding the 'valueprop to theuseField` config, but your sandbox already has that so I don't know why it's not working.

leonardopolly commented 3 years ago

@AdrienAgnel If you change your values to strings it will work. value={50} to value="50" Apparently, radio fields in FF cannot have non-string types. #917