-
Notifications
You must be signed in to change notification settings - Fork 58
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
fill() isn't populating checkboxes #75
Comments
@ataylor32 , the comparison for determinate if the field is checked or not is made using You should use the same values and types, for this check work as expected.
// Post model:
...
getAllowCommentsAttribute($value){
return $value ? '1' : null;
}
...
// on Controller:
$data = $post->toArray();
$data['allow_comments'] = $data['allow_comments'] ? '1' : null;
// on View:
{!! Form::open()->fill($data) !!}
{!! Form::checkbox('allow_comments', 'Allow comments?', '1', $post->allow_comments)!!}
{!! Form::checkbox('allow_comments', 'Allow comments?', '1')->checked($post->allow_comments)!!} |
Thanks for your time and input on this! Since the
With this approach, it's the same values as what Laravel uses by default, only as a string ( My question is: why didn't changing the third parameter of Thanks again for your help! |
@ataylor32 you are right, no make sense change model attributes only for work a form field (is too aggressive). I will make additional tests here (create a database, with a table, with a boolean field and try to simulate the same scenario). In my opinion, since Laravel knows this field is a boolean, maybe the Laravel apply some cast and already there is an internal I will make some tests to see the results, but I think when the field was a checkbox/radio, I can change the verification, using another approach instead of |
Do you have a guess as to when you might have a chance to work on this? It's fine if you don't, but I thought I'd ask. Also, would it help if I created a simple project demonstrating the bug? |
Bug seems to exists in that line of code laravel-bootstrap-4-forms/src/FormBuilder.php Line 266 in 47eef3e
$formData[$name] (true) is compared with $value ("on") |
Here is my form:
The
allow_comments
field is a boolean field, as you can see in the migration file:When I go to edit a post that has its
allow_comments
field set to1
, the checkbox renders as unchecked. I would expect it to render as checked.The text was updated successfully, but these errors were encountered: