Skip to content

Fix #974: Use parse instead of format in checkbox/radio checked logic#1074

Merged
erikras merged 2 commits intomainfrom
fix/issue-974-checkbox-parse
Feb 13, 2026
Merged

Fix #974: Use parse instead of format in checkbox/radio checked logic#1074
erikras merged 2 commits intomainfrom
fix/issue-974-checkbox-parse

Conversation

@erikras-richard-agent
Copy link
Contributor

@erikras-richard-agent erikras-richard-agent commented Feb 13, 2026

Fixes #974

Problem

In useField.ts, getInputChecked() uses format(value, name) to transform the value before comparing to _value. But _value is in internal format while format converts to display format. This causes type mismatches (e.g. comparing string "10" to number 10 fails strict equality).

Solution

Use parse instead of format in getInputChecked(). This compares the parsed internal value with the raw _value attribute, ensuring type consistency.

Tests

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

Summary by CodeRabbit

  • Tests

    • Added tests to verify correct selection state for radio and checkbox controls when forms are initialized with prefilled values.
  • Bug Fixes

    • Fixed value comparison logic so radio and checkbox controls reflect initial values correctly by applying the proper value transformation during initialization.

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.
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Updated field-checked logic to use parse() when computing checked state for radio and checkbox inputs; added tests that verify parse/format integration for radio and checkbox controls using initialValues and data-testid assertions.

Changes

Cohort / File(s) Summary
Tests
src/Field.test.js
Added tests validating format/parse integration for radio and checkbox controls, checking initial selection for single-value and multi-value fields.
Hook logic
src/useField.ts
Changed getInputChecked to use parse(value, name) for checkbox and radio comparisons; removed defaultIsEqual declaration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble bugs with careful art,

parsing values, doing my part.
Radios hum and checkboxes sing,
tests applaud the order I bring.
Hooray — no more mismatched thing!

🚥 Pre-merge checks | ✅ 4 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (5 files):

⚔️ src/Field.test.js (content)
⚔️ src/Field.tsx (content)
⚔️ src/types.ts (content)
⚔️ src/useField.ts (content)
⚔️ typescript/index.d.ts (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: replacing format with parse in checkbox/radio checked logic, directly addressing issue #974.
Linked Issues check ✅ Passed All code changes implement the linked issue #974 requirements: parse replaces format in checkbox/radio checked logic, and tests verify format/parse interactions with numeric values.
Out of Scope Changes check ✅ Passed All changes are within scope: test additions verify the checkbox/radio fix and removal of unused defaultIsEqual helper aligns with the parse/format logic changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-974-checkbox-parse
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch fix/issue-974-checkbox-parse
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉


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

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 13, 2026
src/useField.ts Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed — removed unused defaultIsEqual. Good catch.

@erikras erikras merged commit 21d9f3b into main Feb 13, 2026
4 checks passed
@erikras erikras deleted the fix/issue-974-checkbox-parse branch February 13, 2026 18:03
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.

2 participants