final-form / final-form/react-final-form

[Bug] Value on checkbox fields no longer printed in DOM correctly when not specified

Open
#843 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

### Are you submitting a **bug report** or a **feature request**?

bug report

### What is the current behavior?

Given an input field of type "checkbox" without any specified value no longer outputs a DOM element with the value specified as true. This was changed with the following commit: https://github.com/final-form/react-final-form/commit/abd6d6266d2f6953a1995cb3dedd26f198e653fc (line 210). Before there where some logic that resolved if the given value to the checkbox was undefined the actual value from the form state was used.

This issue does not affect asynchronous forms since things are correctly resolved under the hood in final-form, but for synchronous form posts this becomes an issue since no value will be sent to the back-end.

### What is the expected behavior?

The DOM element should have a proper value resolved. If no value are given as input it should use the old logic of resolving the value based on initial values in the form.

### Sandbox Link

```
// @flow
import React from "react";
import { Form, Field } from "react-final-form";

export const Issue = () => {
return (
{
// Disable final form internal so we can submit our form,
// see https://github.com/final-form/react-final-form/issues/332
const doSubmit = () => handleSubmit(undefined);

return (



Active

Submit

);
}}
/>
);
};
```

### What's your environment?

"final-form": "4.20.1"
"react-final-form": "6.5.1"

### Other information

This is related to synchronous forms which can be debated if final-form supports, https://github.com/final-form/react-final-form/issues/332.

The easiest workaround is to have a custom input for check-boxes that resolves the values properly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.