fix: align DOM checkbox and radio parsing with browsers#99
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc059ef758
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case "radio": | ||
| if (fieldNode.checked && fieldNode.value === "false") { | ||
| return false; | ||
| } | ||
|
|
||
| if (fieldNode.checked && fieldNode.value === "true") { | ||
| return true; | ||
| } | ||
|
|
||
| if (fieldNode.checked) { | ||
| return fieldNode.value; | ||
| } | ||
|
|
||
| return null; | ||
|
|
||
| case "checkbox": | ||
| if (fieldNode.checked && fieldNode.value === "true") { | ||
| return true; | ||
| } | ||
|
|
||
| if (!fieldNode.checked && fieldNode.value === "true") { | ||
| return false; | ||
| } | ||
|
|
||
| if (fieldNode.checked) { | ||
| return fieldNode.value; | ||
| } |
There was a problem hiding this comment.
Preserve indexed row positions for checkbox/radio fields
For forms that use indexed names like items[0].selected / items[1].selected, omitting every unchecked checkbox/radio here corrupts the parsed array shape. entriesToObject() compacts indexed paths by encounter order in packages/core/src/index.ts (setPathValue), so a form where only items[1].selected is checked now parses as items[0].selected, attaching the checked state to the wrong row. The previous false placeholder avoided that reindexing, so this is a real data-corruption regression for checkbox/radio-only indexed collections or repeated rows whose only indexed field is a boolean.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Checked this against the current parser and reproduced it. The outcome is real, but it is not specific to #99: it comes from the existing documented sparse-index compaction rule in @form2js/core, which already compacts any omitted indexed entry (for example, a lone items[1].name also becomes items[0].name). Reintroducing unchecked checkbox placeholders here would undo the browser-aligned DOM behavior we intentionally restored in #99. Follow-up in #100 adds an explicit DOM test for this interaction and documents that omitted unchecked indexed controls do not reserve compacted array slots, so callers that need stable row identity should submit another field for that row.
Summary
Test Plan
Summary by cubic
Aligns
@form2js/domcheckbox and radio parsing with native browser form submission. Removes legacy boolean coercion: checked controls emit their string value; unchecked controls are omitted.Bug Fixes
"true"/"false"coercion for checkbox/radio in@form2js/dom.README.mdanddocs/api.mdto reflect browser-aligned behavior.Migration
Written for commit fc059ef. Summary will update on new commits.