-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wire:modeling checkboxes to sub-key of array adds extra ""
checked item
#896
Comments
@benborgers To avoid the extra blank entry, try initializing the
or
|
That works, thank you! Is binding to an undefined key undefined behavior in Livewire? Or is this a different code path that has a small bug? |
You're welcome @benborgers ! To the best of my understanding, if you don't initialize an array used in a In my apps, I make sure I initialize all properties used in my |
@benborgers thanks for the report! Yeah seems like a bug in how the checkbox groups are initialised. For future reference, this is what the Volt component would look like (basically the same, just one file) 😉 <?php
use Livewire\Volt\Component;
new class extends Component {
public array $notifications = [];
};
?>
<div>
<div>
@json($notifications)
<flux:checkbox.group wire:model.live="notifications.subkey" label="Notifications">
<flux:checkbox label="Push notifications" value="push" />
<flux:checkbox label="Email" value="email" />
<flux:checkbox label="In-app alerts" value="app" />
<flux:checkbox label="SMS" value="sms" />
</flux:checkbox.group>
</div>
</div> |
Flux version
v1.1.0
Livewire version
v3.5.17
What is the problem?
When a set of Flux checkboxes wire:modeled to
someProperty.subkey
, the first item in the array is""
.For example:
["", "first_selection", "second_selection"]
. When nothing is selected, it's[""]
.2024-12-19.at.12.32.29.mp4
Code snippets
(not Volt, sorry!)
How do you expect it to work?
If zero checkboxes are checked, the array's length should be 0; if 1 checkbox is checked, the array's length should be 1; etc.
Please confirm (incomplete submissions will not be addressed)
The text was updated successfully, but these errors were encountered: