Wire:click on <select>

How do I trigger a “on change” on a select field?

Basically I want to call a method when a an option from a is selected

Thanks

You can hook into when your model is updated. Something like this:

component.blade.php

<select wire:model="foo">
    <option></option>
    <option>1</option>
    <option>2</option>
</select>
Component.php

public $foo;

// the updated* method follows your variable name and is camel-cased, in this sample, 'foo'
public function updatedFoo()
{
    // your code you want to execute
}

More on hooks here: https://laravel-livewire.com/docs/lifecycle-hooks

1 Like

The problem here was that I wasn’t thinking “Livewire”, assigning it to a model and checking in hydrate() did the trick but your solution makes more sense. Thanks!

My confusion was because the is only shown when another model/attribute is a specific value which has it’s own logic when a value is selected.

1 Like