New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Checkbox loses attribute "value" #2922
Comments
Also experiencing this too. This looks like regression in 6.7.0. If you inspect the Employed checkbox input between these two versions, you'll see the error too. Or just look at the values output between the two. http://redux-form.com/6.7.0/examples/simple/ http://redux-form.com/6.6.3/examples/simple/ |
Why value may by only |
Same here, unchecked checkbox yields empty value instead of false. Rolled back to 6.6.3 and it works there. |
I am not need |
having the same issue. Locking out to 6.6.3 fixes it. Would be great to see how we could work around this. Because now if checkbox is checked and then unchecked its payload is "" (empty string) and is removed from form's state :( |
Experimented the same issue - the onBlur method set it empty |
also, i'm curious why the decision was made for checkbox field to be removed from form state altogether? It's a checkbox and it cannot be undefined, because this is a field with value, either checked or unchecked, IMO this cannot be checked or non-existant_field |
Can anybody tell me why the value is replaced to a boolean type? <form>
<input type="checkbox" name="list[]" value="1">
<input type="checkbox" name="list[]" value="2">
<input type="checkbox" name="list[]" value="3">
</form In this case boolean is nothing! In state will be selected checkbox value, not |
@Slavenin - you can label the checkboxes with anything you like ("1", "2" etc), but each checkboxes' value will be either |
@jacklj, you're wrong. See my example code in previous comment. Where you see |
@Slavenin - I think you are right, but all previous versions worked with true/false values so the functionality should be restored first. |
@kromit, maybe, if input having not empty attribute value - use him, if not - using true/false |
|
I'm having this problem too. |
This is possibly going to be something really simple, but with the solution using normalize mentioned above, i can see that the values of unchecked boxes are false: However all of the false values (and keys) are nonexistent in |
@Slavenin's issue has been completely hijacked by people essentially re-reporting #3162 but is this is not the issue being reported here. @Slavenin this is an interesting point. I'm not 100% certain why or when the decision was made that checkboxes have only boolean values, but it was mostly likely that it was the most sensible default behaviour. You can stray from the default by creating a custom checkbox component. For example, you can change the onChange handler like so:
|
@danielrob, something like this i do. But this is wrong because |
I'd like to bump this issue and start out by saying that I'm really surprised that the checkbox behavior is implemented this way. Assuming that a checkbox is simply a boolean input of true or false (true or '' actually) is not correct and is directly opposed to how normal HTML checkboxes are expected to behave. Having multiple checkboxes (FieldArray) with this project makes them basically useless without creating a HOC or other "corrective" measures. For more information on how checkboxes are expected to behave, I submit the MDN documentation. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox |
The checkbox behavior with |
Fixed by #3482. |
if you want to have an array of checkbox values instead of booleans, you can use this quick and dirty checkbox component: |
Published fix in |
The problem seems to be fixed in the new release |
Like radio buttons, the right way to do checkboxes when they are all related options is to: - use the same "name" for all of them - use different "value"s and "id"s If the name was "energySource", and values were "oil" and "electricity", the URL params for the submitted form would look like `?energySource=oil&energySource=electricity`. As documented on MDN: - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Examples *** For some reason, Redux forms breaks this behaviour. - all "value"s are overwritten to either "true" or "false" - all checkboxes with identical "name"s are selected as a group I found a few links to this behaviour. - https://www.reddit.com/r/reactjs/comments/4enekc/redux_form_question/ - redux-form/redux-form#2922 - redux-form/redux-form#1993 In order to get the right way of doing things to work, we'd have to manage the behaviour ourselves, which is not something I am interested in. Changing the "name"s of our checkboxes so that we can just move forwards with this.
Like radio buttons, the right way to do checkboxes when they are all related options is to: - use the same "name" for all of them - use different "value"s and "id"s If the name was "energySource", and values were "oil" and "electricity", the URL params for the submitted form would look like `?energySource=oil&energySource=electricity`. As documented on MDN: - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Examples *** For some reason, Redux forms breaks this behaviour. - all "value"s are overwritten to either "true" or "false" - all checkboxes with identical "name"s are selected as a group I found a few links to this behaviour. - https://www.reddit.com/r/reactjs/comments/4enekc/redux_form_question/ - redux-form/redux-form#2922 - redux-form/redux-form#1993 In order to get the right way of doing things to work, we'd have to manage the behaviour ourselves, which is not something I am interested in. Changing the "name"s of our checkboxes so that we can just move forwards with this.
Like radio buttons, the right way to do checkboxes when they are all related options is to: - use the same "name" for all of them - use different "value"s and "id"s If the name was "energySource", and values were "oil" and "electricity", the URL params for the submitted form would look like `?energySource=oil&energySource=electricity`. As documented on MDN: - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Examples *** For some reason, Redux forms breaks this behaviour. - all "value"s are overwritten to either "true" or "false" - all checkboxes with identical "name"s are selected as a group I found a few links to this behaviour. - https://www.reddit.com/r/reactjs/comments/4enekc/redux_form_question/ - redux-form/redux-form#2922 - redux-form/redux-form#1993 In order to get the right way of doing things to work, we'd have to manage the behaviour ourselves, which is not something I am interested in. Changing the "name"s of our checkboxes so that we can just move forwards with this.
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. |
I create a checkbox with stateless function and set value. If checkbox changed - my value set to true or false. If i uncheck checkbox why checkbox exists in state? In simple html form if checkbox is not checked by form submit he not submited to server.
In previous version value in state be true or false. Now - true or undefined. But not value that i set in start
Sandbox link https://jsfiddle.net/Slavenin/o31L5ns2/2/
The text was updated successfully, but these errors were encountered: