Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel Livewre: on select change, pass the selected value into the method in wire:change

i have this select tag on Livewire component:

<select 
    class="form-select deliveryGuySelect" 
    id="order-{{THIS_NEED_TO_BE_$dg->id}}" 
    wire:change="assignOrder({{$order->id}})"
>
    @foreach($deliveryGuys as $dg)
       <option value="{{$dg->id}}" wire:key="{{$dg->id}}">{{$dg->name}}</option>
    @endforeach
</select>

And I need, on assignOrder() action from select tag, to send the option value as parameter $dg->id.

How can I do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Livewire and Alpine together expose the $event magic action-object, which can target the option that was selected, and the value it has, by using $event.target.value

<select wire:change="setSomeProperty($event.target.value)">
    <!-- Options here -->
</select>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading