vendredi 25 mai 2018

Laravel checkbox checked issue

I am using form model binding and I have a check box field in my edit form.

       <div class="form-group">
            <div class="form-check">
                {!! Form::checkbox('is_played', 1, $game->is_played === 1 ? true : false, ['id' => 'is-game-played-check', 'class' => 'form-check-input', 'autocomplete' => 'off']) !!}
                <input type="hidden" name="is_played" value="0">
                <label class="form-check-label" for="is-game-played-check">
                    IS played ?
                </label>
            </div>
        </div>

When I come to my edit view, every other field in the form gets populated without any problem but checkbox does not get checked when the condition $game->is_played === 1 is ensured. I also noticed that when I refresh the page checkbox get checked if the condition $game->is_played === 1 is ensured.

I also tried using HTML instead of Laravel's form helpers and again it worked without any problem.

<input id="is-game-played-check" class="form-check-input"  name="is_played" type="checkbox"value="1">

What can be the issue here ?

Any help would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire