robsontenorio / mary

Laravel Blade UI Components for Livewire 3
https://mary-ui.com
Other
1.06k stars 135 forks source link

Checkbox issue #581

Closed fadyelgendy closed 2 months ago

fadyelgendy commented 3 months ago

maryUI version

1.35.6

daisyUI version

4.12.10

Livewire version

3

What browsers are affected?

Firefox, Chrome

What happened?

can not change/set checkbox value. it always default to true.

robsontenorio commented 3 months ago

No errors on console?

Are you sure that you have “wire:model” in place ? Please, take a look again on docs.

fadyelgendy commented 3 months ago

@robsontenorio no console errors. and here is the full scenario

model property

    public array $opts = [];

component

    @foreach($methods as $opt)
        <x-checkbox wire:model="opts.{{$loop->index}}.method" value="{{ $opt['id'] }}" :label="$opt['name']" />
    @endforeach

here is the result Screenshot from 2024-08-19 20-21-12

robsontenorio commented 2 months ago

The concept of multiple checkbox works differently in Livewire. https://livewire.laravel.com/docs/wire-model#multiple-checkboxes

public array $methods = ["one", "two", "three"];
public array $opts = [];
@foreach($methods as $opt)
    // There is no "index" and you must bind it to an array model
   <x-checkbox wire:model="opts" :value="$opt" :label="$opt" />
@endforeach