-
-
Notifications
You must be signed in to change notification settings - Fork 102
Fix issues with boolean values #256
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
base: main
Are you sure you want to change the base?
Conversation
This fixes an issue with boolean values on inputs. An more specifically if the value is false the string casting ((string) $value) produces an empty string instead of 'false'. Moreover true produces '1' which is probably not the expected behavior when a user passes true as $value.
I also noticed that the strict comparison in radio button and true/ false values is also unsuitable as in an implementation without the package it would be something like old('field', $model->field) == 'true' as the old() function returns strings but model returns boolean values in this case. So would it be ok to change this line |
Could you add tests for this? |
public function radio($name = null, $checked = null, $value = null) | ||
{ | ||
{ | ||
$value_as_string = is_bool($value) ? json_encode($value) : $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never use snake case for variables names. Please use package conventions.
This fixes an issue with boolean values on inputs. And more specifically if the value is false (boolean) the string casting ((string) $value) produces an empty string instead of 'false'. Moreover true produces '1' which is probably not the expected behavior when a user passes true as $value.
Even when a user try to avoid the issue by passing string values ('true', 'false'), if the model values passed through html()->model() are boolean then there are not auto-selected as the strict comparison of the values doesn't work.
This PR fixes the problem for all cases as long as are consistent with form values and model values.
Examples of current behavior:
Examples of behavior after fix: