Choices-js / Choices

A vanilla JS customisable select box/text input plugin ⚡️
https://choices-js.github.io/Choices/
MIT License
6.07k stars 601 forks source link

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

Open Briareos17 opened 3 years ago

Briareos17 commented 3 years ago

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):

Briareos17 commented 3 years ago

Any suggestions?

ParadiseFallen commented 3 years ago

you can use this image

Briareos17 commented 3 years ago

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.

flymke commented 2 years ago

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']; }

Briareos17 commented 2 years ago

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

flymke commented 2 years ago

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

Briareos17 commented 2 years ago

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.

EdOzolins commented 1 year ago

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}.

dawid7766 commented 1 year ago

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

mutschler commented 3 months ago

anyone got a working solution for this?