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 fields are not handled correctly

See original GitHub issue

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

Whenever updating the form container, if the form has a multiple checkbox field, resulting in an array being created for it, it will improperly reset the field/form current values. (It will also reset any other field value if you have it). Also, if you change anything and then undo your changes, it will have an incorrect dirty state set (in regards to initialValues). Ex: toggle on/off a single checkbox, the dirty state should be false.

The issue can be reproduced here: https://codesandbox.io/s/ovxvw4oknz

Perform any changes in the form, then click on the Click here to improperly reset the form (you might have to click twice) button at the bottom. The button only changes the state of the form container (App component), so it has nothing to do with the form state.

What is the expected behavior?

The form should not be improperly reset, the values should be kept (the same way it happens when you don’t have a checkbox/array field, check this other sandbox where I replaced the array:

Sandbox Link

https://codesandbox.io/s/k2y9w503l5

The form now doesn’t reset if its container state changes.

What’s your environment?

Latest stable final-form and react-final-form

Other information

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NateRadebaughcommented, Jul 25, 2019

Hey @apostololeg, here’s the workaround I used in my code: https://codesandbox.io/s/rff-checkbox-touched-z86x8

image

1reaction
Mesqalitocommented, Apr 22, 2019

@gustavovnicius It’s a common mistake when using React. The form is being reset because your initialValues have actually changed during render due to a fact that it’s an object literal that is created each time you enter render method, thus, having new reference. Save initialValues somewhere (in this, for example) and pass it to form and problem solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkboxes broken [#2926437] | Drupal.org
Checkboxes are not being handled correctly by conditional_fields/src/Plugin/conditional_fields/handler/OptionsButtons.php - tried in Druapl ...
Read more >
Unable to handle multiple input type checkbox fields in React
So I have this component where I have around 15 input type checkboxes, which upon checked/unchecked show/hide images. All fields have an ...
Read more >
Not able to check the Checkbox on Salesfoce standard page ...
We have custom checkbox field (Is Active) on the standard page layout, check box is not able to check when we click on...
Read more >
Datagrid checkboxes not handling dirty flag correctly
One of the columns is "IsSelected", and if that is true in the database, it should be checked. That part is working. Once...
Read more >
<input type="checkbox"> - HTML: HyperText Markup Language
Note: If a checkbox is unchecked when its form is submitted, there is no value submitted to the server to represent its unchecked...
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