Skip to content

Stop a validation checkbox from flipping the switch above it - #209

Merged
jodeleeuw merged 1 commit into
testfrom
fix/validation-checkbox-id-collision
Aug 27, 2026
Merged

Stop a validation checkbox from flipping the switch above it#209
jodeleeuw merged 1 commit into
testfrom
fix/validation-checkbox-id-collision

Conversation

@jodeleeuw

Copy link
Copy Markdown
Member

The bug

In /admin/<experiment>, ticking Allow CSV or Allow JSON turned data validation off and collapsed the block the checkbox lives in. The click did the opposite of what it said, and the setting it silently changed is the one that decides whether malformed submissions are rejected before they reach the researcher's storage provider.

Cause

An id collision, not anything in the validation logic.

Ark derives a control's hidden-input id from the surrounding Field context — useSwitch and useCheckbox both do:

ids: { label: field?.ids.label, hiddenInput: field?.ids.control }

SettingsRow rendered its children inside the row's own Field.Root, so both checkboxes were handed the same DOM id as the master switch's hidden input. Checkbox.Root is itself a <label htmlFor={thatId}>, and the browser resolves a label to the first element in the document carrying that id — the switch, which renders above. So clicking the checkbox activated the switch.

Fix

The Field.Root now wraps only the switch and its label/description; SaveError and children move out to an enclosing Stack.

Dependent controls elsewhere (the numeric inputs in ExperimentActive, the required-fields input in ExperimentValidation) each open their own Field.Root already, so they were never affected and stay unaffected. Only controls that inherited the row's field were broken by it — which is why the fix belongs in SettingsRow rather than in any one call site.

Tests

Five cases added to __tests__/experiment-validation.test.jsx. They click the labels, not the inputs: clicking an input directly never went through the broken path, so a test that does that passes either way. Three of the five fail against the previous SettingsRow and pass now.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SHZNijLwUhn26yCbYbn1UN

Ticking "Allow CSV" or "Allow JSON" in the admin panel turned data
validation off and collapsed the block the checkbox lives in. The
researcher's click did the opposite of what it said, and the setting it
silently changed decides whether malformed submissions are rejected.

The cause was an id collision, not anything in the validation logic. Ark
derives a control's hidden-input id from the surrounding Field context --
`useSwitch` and `useCheckbox` both do `ids: { hiddenInput:
field?.ids.control, label: field?.ids.label }`. SettingsRow rendered its
`children` inside the row's own `Field.Root`, so both checkboxes were
handed the SAME DOM id as the master switch's hidden input.
`Checkbox.Root` is itself a `<label htmlFor={thatId}>`, and the browser
resolves a label to the FIRST element carrying that id -- the switch,
which renders above. So the click activated the switch.

The Field now wraps only the switch and its label; `SaveError` and
`children` move out to an enclosing Stack. Dependent controls elsewhere
(the numeric inputs in ExperimentActive, the required-fields input) each
open their own `Field.Root` already, so they were never affected and are
unaffected by this -- only controls that INHERITED the row's field were
broken by it, which is why the fix belongs in SettingsRow rather than in
any one call site.

Tests click the labels, not the inputs: clicking an input directly never
went through the broken path, so a test that does that passes either way.
Three of the new cases fail against the previous SettingsRow.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SHZNijLwUhn26yCbYbn1UN
@jodeleeuw
jodeleeuw merged commit 7a08ab0 into test Aug 27, 2026
1 check passed
@jodeleeuw
jodeleeuw deleted the fix/validation-checkbox-id-collision branch August 27, 2026 11:40
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.

1 participant