laravel-bootstrap-4-forms
laravel-bootstrap-4-forms copied to clipboard
checkboxes don't get checked.
Hello,
While filling the form with eloquent data doesn't work for checkboxes. It isn't actually possible to set the checked state.
Reproduction:
Using bootstrap from npm with:
"bootstrap": "^4.0.0",
Using this package through composer:
"netojose/laravel-bootstrap-4-forms": "^3.0"
Tried:
{!! Form::checkbox('post_is_equal', __('site.customer.post_is_equal'), 1, true) !!}
{!! Form::checkbox('post_is_equal', __('site.customer.post_is_equal'), 'on', true) !!}
{!! Form::checkbox('post_is_equal', __('site.customer.post_is_equal'), '1', true) !!}
{!! Form::checkbox('post_is_equal', __('site.customer.post_is_equal'))->checked() !!}
{!! Form::checkbox('post_is_equal', __('site.customer.post_is_equal'))->checked(true) !!}
All of the above result in an unchecked checkbox. Maybe some breaking change in bootstrap that renders this unusable?
Update. Only happens if the checkbox name (first parameter) is also a column name in the data you use to fill the form.
This bug still persists. I can confirm it is when you are using fill() and the name is one of the fields.
I avoid the problem like this:
public function getMyCheckboxAttribute()
{
return $this->attributes['my_checkbox'] ? 'on' : 'off';
}