Search code examples
laravel-livewire

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?


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>