mercredi 21 décembre 2016

How should I work with checkbox in laravel?

In my create.blade.php I have the following code:

<div class="form-check">
        <label for="active">active</label>
        <input id="active" name = "active" type="checkbox" class="form-check-input" value="1">
    </div>

And in my edit.blade.php the following:

<div class="form-check">
            <label for="active">active</label>
            <input id="active" name = "active" type="checkbox" class="form-check-input" value="{!!$company->
            active!!}"> 
        </div>

  1. When submitting either with the checkbox checked they work fine
  2. When editing a record with active set to 1, the checkbox isn't checked when opening the form

I know there's no value when not checked and when opening the checkbox isn't 'on' because the value is 1 instead of 'on'.

How can I resolve this problem?




Aucun commentaire:

Enregistrer un commentaire