adis
adis

Reputation: 5951

How to add boolean attributes / data-attributes in Play 2.0 templates?

does anybody know how to add boolean attributes like autofocus to scala templates?

Example: autofocus:

<input autofocus />

For now I use:

'autofocus -> "autofocus"

This prints:

<input type="text" autofocus="autofocus" />

And how to add custom data-attributes? Thanks!

Upvotes: 2

Views: 517

Answers (2)

Fernando Correia
Fernando Correia

Reputation: 22375

Use None, like this:

@inputText(
  loginForm("username"),
  '_label -> Messages("usernameLabel"),
  'required -> None,
  'autofocus -> None
)

It will output an element like this:

<input type="text" id="username" name="username" value="" required autofocus>

Upvotes: 1

adis
adis

Reputation: 5951

This works, but still I (hope) think there should be an easier way in scala!

'autofocus -> "autofocus"

Upvotes: 0

Related Questions