Skip to content

Use parse instead of format when calculating checked#974

Closed
jharding wants to merge 1 commit intofinal-form:mainfrom
jharding:bug/fix-parse-format-radio-checkbox
Closed

Use parse instead of format when calculating checked#974
jharding wants to merge 1 commit intofinal-form:mainfrom
jharding:bug/fix-parse-format-radio-checkbox

Conversation

@jharding
Copy link

This may be an incorrect assumption, but it seems like the getter for checked should be using parse, not format when comparing values. In addition to fixing an issue I was experiencing, the TypeScript definitions suggest this should be the intended behavior as well as parse returns FieldValue and state.config is of the type FieldValue.

I added a couple of tests to prevent future regressions – please let me know if there's anything else I should do to get this to a state where you'd be comfortable accepting the patch.

Thanks for the great library!

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9839445:

Sandbox Source
React Final Form - Simple Example Configuration
React Final Form - Synchronous Record Level Validation Configuration
React Final Form - Synchronous Field Level Validation Configuration
final-form/react-final-form Configuration
React Final Form - Subscriptions Example Configuration

@@ -161,14 +161,14 @@ function useField<FormValues: FormValuesShape>(
get checked() {
let value = state.value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value should probably be const as you can call parse right here, then you could remove line 164 and change 171 to `return value === _value"

@nkappler
Copy link

I'm not a maintainer, just interested in this PR as I stumbled upon it due to this bug #560

Copy link
Contributor

@erikras-richard-agent erikras-richard-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Richard (Team Lead)

Fix to use parse instead of format when calculating the checked prop. This PR has merge conflicts and is from 2022 — the logic may still be relevant but would need rebasing. Will evaluate whether the fix applies to current code.

@erikras-richard-agent
Copy link
Contributor

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Warning

Rate limit exceeded

@erikras-richard-agent has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@erikras-richard-agent
Copy link
Contributor

Thank you for catching this subtle bug with parse vs format for radio/checkbox checked calculation, @jharding! This PR targets the old JS codebase which has since been rewritten in TypeScript, so it's no longer directly mergeable. We'll evaluate whether the underlying issue still exists in the current code. Closing with appreciation. 🙏

erikras-dinesh-agent pushed a commit that referenced this pull request Feb 13, 2026
The bug: getInputChecked() used format() to transform the value before
comparing to _value. But _value is in internal format while format()
converts to display format, causing type mismatches (e.g. string "10"
vs number 10).

Fix: Use parse() instead of format() in checkbox/radio checked logic.
This compares the parsed internal value with the raw _value attribute.

Added tests with numeric radio/checkbox values using format/parse to
prevent future regressions.
erikras pushed a commit that referenced this pull request Feb 13, 2026
…#1074)

* Fix #974: Use parse instead of format in getInputChecked

The bug: getInputChecked() used format() to transform the value before
comparing to _value. But _value is in internal format while format()
converts to display format, causing type mismatches (e.g. string "10"
vs number 10).

Fix: Use parse() instead of format() in checkbox/radio checked logic.
This compares the parsed internal value with the raw _value attribute.

Added tests with numeric radio/checkbox values using format/parse to
prevent future regressions.

* chore: remove unused defaultIsEqual

---------

Co-authored-by: erikras-dinesh-agent <dinesh@openclaw.dev>
Co-authored-by: erikras-richard-agent <richard@openclaw.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants