React-final-form: Only strings can be used as value radio buttons.

Created on 9 Apr 2018  路  5Comments  路  Source: final-form/react-final-form

Hi @erikras , thank you for your great library. I am running into some issues with radio buttons in particular.

Bug report

I want to use a number as the value, but I do not checked the radio button. I clicked and the value was recorded, but the input did not respond.

Sandbox Link

Edit 馃弫 React Final Form - Simple Example

Most helpful comment

Ah, yes. The problem is that the DOM only gives string values for inputs. e.g. typeof event.target.value === 'string' is always true. You can get around this by adding a
parse={Number} prop to all your Field components. This will convert the string that the DOM gives back into a Number for storage in the JSON. Then the valueFromState === valueProp check will work for deciding which radio button should be checked. Parse docs.

All 5 comments

I smell an === bug, my favorite of all javascript problems. 馃槅

Ah, yes. The problem is that the DOM only gives string values for inputs. e.g. typeof event.target.value === 'string' is always true. You can get around this by adding a
parse={Number} prop to all your Field components. This will convert the string that the DOM gives back into a Number for storage in the JSON. Then the valueFromState === valueProp check will work for deciding which radio button should be checked. Parse docs.

Thank you. To understand that my problem is in number, I spent 16 hours of my life 馃槅

I think you mean "16" hours. 馃ぃ Glad it's remedied!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gsantiago picture gsantiago  路  5Comments

czterystaczwarty picture czterystaczwarty  路  4Comments

niros-welldone picture niros-welldone  路  3Comments

mewben picture mewben  路  3Comments

kavink picture kavink  路  5Comments