1

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks that works, only confusing thing is that the checkbox does not have a checked attribute when checked=true (in the inspector) see scalafiddle.io/sf/81rACVu/0
checked={true} set the property checked of the <input>, while checked="checked" set the attribute checked.
The property defaultChecked is mapped to the attribute `checked.
The property checked is not mapped to any attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.