davidkpiano / react-redux-form

Create forms easily in React with Redux.
https://davidkpiano.github.io/react-redux-form
MIT License
2.06k stars 252 forks source link

Inconsistent behavior between native and custom controls with boolean-valued radio buttons #779

Open tmcdonnell87 opened 7 years ago

tmcdonnell87 commented 7 years ago

The Problem

When using native controls, it is possible to create a boolean-valued radio button, such as:

       <Control.radio
          model=".choice"
          value={false}
          required
        />

However, when you create the same button and pass in a component, the boolean value is translated to a string, and thus doesn't allow the button to be clicked.

        import Radio from 'react-bootstrap/lib/Radio';
        <Control.radio
          component={Radio}
          model=".choice"
          value={false}
          required
        >Boolean false</Control.radio>

Steps to Reproduce

See reproduced example. Note that, in the top section, clicking the Boolean true option does nothing, and the Boolean false option matches the String false option. In the bottom section, all radio buttons work as expected.

Expected Behavior

Radio button behavior is consistent even when using custom controls.

Actual Behavior

Boolean values are converted to strings in state, and thus do not match the control value.

Reproducible Code Example

https://esnextb.in/?gist=98695ff117787fcdc4a3a10245cd0582

stevenmason commented 7 years ago

On react-redux-forms version 1.14.1 this is also happening for the native radio button.

davidkpiano commented 7 years ago

@stevenmason can you whip up a quick CodePen example for that?

stevenmason commented 7 years ago

@davidkpiano You can easily test it in @tmcdonnell87 example by changing the react-redux-forms version to 1.14.1

batoreh commented 7 years ago

I did notice that Control.radio doesn't not support Number values too. It seems to support just String values. I think it would be good if it were at least explained in docs.