v3 needs wired model to be exact boolean in input checkbox #6905
Replies: 6 comments 1 reply
-
Another solution seems to set the checkbox as 'checked="true"' by default. Livewire unchecks it when it needs to or just keeps it checked if the value is set. |
Beta Was this translation helpful? Give feedback.
-
I'm surprised this hasn't been solved yet. Just stumbled across it. FWIW: I was not able to get casting in my model to work. I have to explicitly set it to true/false before it hits the livewire form: $this->is_valid_email = ($wordpressUser->is_valid_email == 1) ? true : false; |
Beta Was this translation helpful? Give feedback.
-
This error has not yet been fixed in v3.4.4.
But this example is not working because value of checkbox in v3 can only be true or false. |
Beta Was this translation helpful? Give feedback.
-
I would also appreciate if this would be handled just like in Livewire 2. Don't really see the benefit of checking for boolean for scripting languages. I tried the Also tried |
Beta Was this translation helpful? Give feedback.
-
I just submitted a failing test PR for this problem. (#8291) Hope to get some clarification soon about this |
Beta Was this translation helpful? Give feedback.
-
else if (el.type === "checkbox") {
if(Array.isArray(value)){
var valueFound=!1;
value.forEach((function(val){
val==el.value&&(valueFound=!0)
})),
el.checked=valueFound
} else {
el.checked=!!value;
}
} I have to replace livewire.esm.js with the livewire 2 and it now working as expected |
Beta Was this translation helpful? Give feedback.
-
Livewire version
v3.0.5
Which PHP version are you using?
PHP 8.2
Repository URL
No response
Steps To Reproduce
Laravel reads and writes boolean values as tinyint(1) into/from MySql database. Livewire v2 understood that '1' is 'true'. But v3 now needs boolean to be real 'true' value to make checkbox checked. There is a solution to write $casts to bool in model class or use 'legacy_model_binding' => true. I believe it is bug and '1' will be used by Livewire v3 as 'true' in future.
Additional information
No response
Please confirm (incomplete submissions will not be addressed)
Beta Was this translation helpful? Give feedback.
All reactions