vendredi 4 juin 2021

Laravel edit form issue with default value for checkbox regarding old value on error

I have a problem and it seems like a bug with Laravel checkbox old() value. I have a code where I want to fill default values on edit and if form submit fails I want to fill old() value to the form. The problem is when original database value is TRUE and new form submit is false for checkbox. Laravel old() does not catch the FALSE value on submit for checkbox and fill the original value which is TRUE.

<input name="active" type="checkbox"
    @if( old('active', $voucher->active ?? false) ) checked='checked' @endif
>

It fall back to default value if submit is FALSE. All solutions I found are wrong. How can I solve it? Thanks for any help.




Aucun commentaire:

Enregistrer un commentaire