jeudi 20 septembre 2018

Checkbox checked attribute not working with Pug

I have the following checkbox written in Pug:

 input(id="favorite" type="checkbox" name="favorite" value='true' checked='#{item.favorite ? true : false}')

When I inspect the item I can see that the logic for the checked attribute is working, showing true or false depending on the situation, but no matter if it is true or false, the checkbox is always selected.

I think the issue might be that, because #{item.favorite ? true : false} is between quotes, the result is not being treated as boolean but as a string. But if I write the code with out quotes it does not work.

My question is, how should I write this so the checked attribute reads the result as boolean?

Thank you.




Aucun commentaire:

Enregistrer un commentaire