elem.checked can have any String value (even an e" /> elem.checked can have any String value (even an e" /> elem.checked can have any String value (even an e"/>

Binding.scala: how to define checked in a Checkbox

351 Views Asked by At

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.

1

There are 1 best solutions below

4
Yang Bo On BEST ANSWER

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.