Skip to content

Preserve checked state of disabled checkbox on submit#195

Merged
lippserd merged 1 commit intomainfrom
fix/checked-and-disabled-checkbox
Mar 26, 2026
Merged

Preserve checked state of disabled checkbox on submit#195
lippserd merged 1 commit intomainfrom
fix/checked-and-disabled-checkbox

Conversation

@sukhwinder33445
Copy link
Copy Markdown
Contributor

Browsers do not submit disabled inputs. Since CheckboxElement's hidden fallback element always used the unchecked value, a checked but disabled checkbox would appear unchecked on the next submit.
Fix renderUnwrapped() to use the checked value in the hidden element when the checkbox is checked and disabled, preserving its state across submissions.

fixes #192

Browsers do not submit `disabled` inputs. Since `CheckboxElement`'s
`hidden` fallback element always used the `unchecked` value, a
`checked` but `disabled` checkbox would appear `unchecked` on the
next submit.
Fix `renderUnwrapped()` to use the `checked` value in the `hidden`
element when the checkbox is `checked` and `disabled`, preserving its
state across submissions.
Copy link
Copy Markdown

@TheSyscall TheSyscall left a comment

Choose a reason for hiding this comment

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

Works as expected.

Changing the value of the hidden element seems like it could have unintended consequences, but I can't think of any case where it wouldn't work.

@sukhwinder33445
Copy link
Copy Markdown
Contributor Author

The value of hidden element is only changed, when the checkbox is checked and disabled. Otherwise it still uses the unchecked value as before.

State Hidden value Checkbox submitted Server receives Before After
Enabled + unchecked n no n
Enabled + checked n yes → y (wins) y
Disabled + unchecked n no n
Disabled + checked n (now → y) no y

@lippserd lippserd added this to the v0.10.1 milestone Mar 26, 2026
@lippserd lippserd merged commit ae2dce6 into main Mar 26, 2026
13 checks passed
@lippserd lippserd deleted the fix/checked-and-disabled-checkbox branch March 26, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabled checkboxes don't auto-populate correctly

3 participants