Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Briareos17 opened this issue Apr 7, 2021 · 10 comments
Labels

Comments

@Briareos17
Copy link

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 Briareos17 added the bug label Apr 7, 2021
@Briareos17
Copy link
Author

Briareos17 commented Apr 12, 2021

Any suggestions?

@ParadiseFallen
Copy link

you can use this
image

@Briareos17
Copy link
Author

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
Copy link

flymke commented Feb 23, 2022

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
Copy link
Author

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
Copy link

flymke commented Feb 23, 2022

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

@Briareos17
Copy link
Author

Briareos17 commented Feb 23, 2022

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
Copy link

EdOzolins commented Oct 25, 2022

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
Copy link

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
Copy link

anyone got a working solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants