Fix x-model setting .value instead of .checked on checkboxes#4779
Fix x-model setting .value instead of .checked on checkboxes#4779calebporzio merged 3 commits intomainfrom
Conversation
PR Review: #4779 — Fix x-model setting .value instead of .checked on checkboxesType: Bug fix What's happening (plain English)
The core issue: Other approaches considered
Changes MadeNo changes made. The PR is clean as submitted. Test Results
Code ReviewThe fix (
The cleanup (
Style: No semicolons, no Minor behavior changes (correctly documented by contributor):
These are technically breaking but the old behavior was a bug, not a feature. SecurityNo security concerns identified. No expression evaluation changes, no VerdictMerge. The fix is architecturally sound — it draws a clean line between Reviewed by Claude |
|
Clarification on Worth noting one subtle public API change: previously, After this PR, The old behavior was arguably incorrect — Low risk in practice, but flagging it for awareness. |
The scenario
Checkbox with
x-modelwith a dotted expression that evaluates toundefined.When this form is submitted, the server receives
agree=""instead ofagree="on".In Laravel, this causes
$request->boolean('agree')to returnfalseeven when the checkbox is checked.The problem
x-modelon checkboxes should only ever control.checked— never.value.However currently, that depends on the type of received value:
valueattributecheckedattributeThis happens because
x-modelusesx-bind:valueunder the hood, which is where this behavior comes from. The problem is that for undefined nested model keys we change the value to''before routing it tox-bind:value.The solution
For checkboxes and radios, set
.checkeddirectly inx-modelinstead of routing throughbind().This also removes the nasty
window.fromModelhack.Breaking changes
This will only cause a breaking change if the user relied on the incorrect behavior:
Before:
<input type="checkbox" value="on">After:
<input type="checkbox" value="agree" checked>Fixes livewire/flux#2497