How do I get jade to render the checked attribute of a checkbox based on a conditional? Like these two versions of the HTML checkbox tag:
This seems to be the ONLY valid version of unchecked:
> <input type="checkbox" name="vehicle" value="Bike">
While this is checked:
> <input type="checkbox" name="vehicle" value="Car" checked="checked">
Here is what I've tried so far:
This Jade is fine:
input(type="checkbox", name="completed", checked=(true===true ? "checked" : "")).checkbox
because it renders this:
<input type="checkbox" name="completed" checked="checked" class="checkbox">
but this Jade is not fine:
input(type="checkbox", name="completed", checked=(false===true ? "checked" : "")).checkbox
because it renders this:
<input type="checkbox" name="completed" checked="" class="checkbox">
instead of this:
<input type="checkbox" name="completed" class="checkbox">
How do I get Jade to render the entire checked attribute instead of just the value of the checked attibute?
You can use:
input(type="checkbox", name="completed", checked=(true===false ? "checked" : undefined))
No need to specify the values:
input(type="checkbox", name="completed", checked=(condition))
If condition is false, there is no checked attribute will added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With