livewire-select icon indicating copy to clipboard operation
livewire-select copied to clipboard

Wire:model not updating on change

Open jasonspick opened this issue 4 years ago • 4 comments

I'm not sure how this works since there is no documentation, but when a value is selected there is no change to the model.

<livewire:user-select wire:model="selectedUser" wire:change="change" name="user_id" value="$selectedUser" placeholder="Choose A User" />

the parent component echos the value selectedUser, but it never changes. If you do this in a standard input form like livewire documents suggest. it works. Am I missing something?

jasonspick avatar Dec 14 '20 15:12 jasonspick

From what I've seen the livewire select component currently just emits an event when it changes values, so as a workaround for the time being you could catch it with a listener like below. What I've done after looking at the code (particularly this part) is something like this:

<livewire:selects.advert-format-select
            name="mediaFormatId"
            :value="$mediaFormatId" />
protected $listeners = [
        'mediaFormatIdUpdated' => 'setMediaFormatId',
];

public function setMediaFormatId($object)
{
        $this->mediaFormatId = $object['value'];
}

Neoglyph avatar Dec 29 '20 13:12 Neoglyph

hello @Neoglyph still not working for me

risqiromadhoni avatar Jan 13 '21 14:01 risqiromadhoni

hello @Neoglyph still not working for me

Which part? Did you create the select class correctly, did you call the listener the correct way and in the correct component class, ... Without an example of your code I can't really help much, not knowing what the issue is.

Neoglyph avatar Jan 13 '21 14:01 Neoglyph

Thanks for sharing this solution. I spend a few days to understand how can get the value, and only need to include a listener into my component and all this.

jcroot avatar Apr 15 '21 21:04 jcroot