question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkbox value breaking pristine state

See original GitHub issue

Hi, I found out that using true/false value within checkboxes is breaking the pristine state value. The case is: Checkbox initial value is probably an empty string. When I set a checkbox to checked state and then uncheck it, the pristine value changes. The flow is ‘’ -> true -> false. You can even check it in the simple example here: http://redux-form.com/6.6.3/examples/simple/

I fixed it by using normalize prop in Field for checkbox component like: <Field normalize={value => value || ''} ... />. Another approach could be setting default initial values for all the checkboxes in each form, which doesn’t make sense at all.

I propose to set as a default behavior true || ‘’ for checkboxes. Then the checkboxes will behave the same way as any other types of inputs.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

22reactions
kgramcommented, Jun 12, 2017

This seems like a very bad solution to the problem. If your checkbox is initialised with an empty string as the value, isn’t the problem this initial wrong value rather than any subsequent correct values?

Since this breaking change was released as a minor version you probably very silently broke most applications using checkboxes in redux-form. It certainly broke mine.

16reactions
dmeenhuiscommented, May 16, 2017

Not sure if intended, but this change now breaks the application I’m currently working on. I’m submitting boolean values from my form to an API which expects the relevant property to be an actual boolean value (true/false).

However, after this change, when I uncheck the box, it now submits an empty string while previously it submitted false. The API cannot convert the empty string to a boolean, so I’m getting an error.

I can work around this by converting the value to an actual boolean before making the API call, or fixing it on the API-side. I’m not really liking either approach though, since it affects every checkbox value I use within the app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reset form as pristine if user changed input values to their ...
I would like to implement the simplest way to actually detect when form is still in its pristine state despite user interacting with...
Read more >
Form's state is pristine, although all checkboxes are selected
The answer is that the pristine state is only changed when the input itself updates the model, not when you update the model...
Read more >
POSTing an Indeterminate Checkbox Value - CSS-Tricks
The checked state of the checkbox is masked by the indeterminate state of the checkbox. If the checkbox was checked when the indeterminate...
Read more >
Shoemaker's pristine streak ends | 06/11/2016 - MLB.com
Matt Shoemaker's streak of 49 strikeouts without issuing a walk comes to an end in the top of the 7th when he walks...
Read more >
Angular directives for Bootstrap - AngularUI
btn-checkbox-false (Default: false ) - Sets the value for the unchecked status. ... uib-btn-radio - $ Value to assign to the ng-model if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found