Choices icon indicating copy to clipboard operation
Choices copied to clipboard

Laravel livewire wire:model directive gets {value: 'value'} instead of 'value' on change

Open Briareos17 opened this issue 3 years ago • 10 comments

Laravel livewire wire:model directive gets {value: 'value'} instead of 'value' on change

Steps to reproduce the behavior: add wire:model to select, init choices and select something.

after selecting something it should return clear value except of json object unless it's multiple

image image image

Desktop (please complete the following information):

  • OS: Windows 10 20H2
  • Browser Chrome
  • Version 89.0.4389.114

Briareos17 avatar Apr 07 '21 16:04 Briareos17

Any suggestions?

Briareos17 avatar Apr 12 '21 11:04 Briareos17

you can use this image

ParadiseFallen avatar Jun 04 '21 11:06 ParadiseFallen

Nope, I'm using a module with internal livewire call, so for now i catching updating hook on livewire side and processing input from choices selects.

Briareos17 avatar Jun 04 '21 11:06 Briareos17

That's what I do too, but it seems there could be a better solution.

if( is_array($this->customer_id) ) { // choices.js value is an array $this->customer_id = $this->customer_id['value']; }

flymke avatar Feb 23 '22 15:02 flymke

That's what I do too, but it seems there could be a better solution.

if( is_array($this->customer_id) ) { // choices.js value is an array $this->customer_id = $this->customer_id['value']; }

Made exactly same thing but this is a crutch

Briareos17 avatar Feb 23 '22 15:02 Briareos17

Actually that works: ... wire:change="$set('customer_id', $event.target.value)"

flymke avatar Feb 23 '22 15:02 flymke

Actually that works: ... wire:change="$set('customer_id', $event.target.value)"

Yep, but, I have module that return me a function in x-data, there I call this.$wire.set() and so on

No matter where to process input, problem is - why I need nested key "value" if there no other keys in input.

Briareos17 avatar Feb 23 '22 15:02 Briareos17

Having the same issue. Echoing a model's value in blade gets actual value, but if inspecting a model ($foo) in the Livewire's hook updatedFoo($value) gets an object of {value: $value}.

EdOzolins avatar Oct 25 '22 19:10 EdOzolins

I had similar problem and found a working solution there: https://forum.laravel-livewire.com/t/select-and-select-multi/1120

However, choices.js was losing style after update DOM, so I added to div with x-data: wire:key="rand()" wire:ignore

dawid7766 avatar Oct 25 '22 20:10 dawid7766

anyone got a working solution for this?

mutschler avatar Mar 27 '24 12:03 mutschler