I want to define a checkbox in Binding.scala, like:
<input type="checkbox"
checked={elem.checked}
/>
elem.checked
can have any String value (even an empty):the checkbox is always checked
.
How can I get
<input type="checkbox"
checked/>
if checked, resp.
<input type="checkbox"/>
if not.
According to https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes , in XHTML 5, any text values means true
.
Fortunately, Binding.scala XML literals allows attributes of Boolean
type. If elem.checked
is false
(not "false"
), the attribute will be removed.