mercredi 14 avril 2021

Laravel livewire - check if checkbox is checked

I have two public variables and both are arrays. Both of them in blade are equal to checkbox input and I need to check if one of them is checked so the other one can be checked at the same time but hidden.

This is my code component:

class Show extends Component
{
    
    public $supplements = [];
    public $supplementsPrice = [];
}

and in my blade:

@foreach($product->supplements as $supp)
   <div class="col-6 pb-1">
      <li class="list-group-item pl-5">
         <input wire:model="supplementsPrice." type="checkbox" value="" class="form-check-input" id="checkbox">
         <input wire:model="supplements" type="checkbox" value="" hidden>
         <label class="form-check-label" for="checkbox"></label>
         <span class="float-right">&euro;</span>
      </li>
   </div>
@endforeach

So if first checkbox with wire:model="supplementsPrice." is checked, the other one must be checked too.

How to do that?




Aucun commentaire:

Enregistrer un commentaire