netojose / laravel-bootstrap-4-forms

Bootstrap 4 forms for Laravel 5/6/7/8
MIT License
183 stars 58 forks source link

checkboxes don't get checked. #91

Closed nepp95 closed 1 year ago

nepp95 commented 4 years ago

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?

nepp95 commented 4 years ago

Update. Only happens if the checkbox name (first parameter) is also a column name in the data you use to fill the form.

vilocity-brian commented 4 years ago

This bug still persists. I can confirm it is when you are using fill() and the name is one of the fields.

koptelovav commented 3 years ago

I avoid the problem like this:

public function getMyCheckboxAttribute()
{
    return $this->attributes['my_checkbox'] ? 'on' : 'off';
}