Scalatags conditional attribute

448 views Asked by At

I'm trying to write a wrapper around the select element. So in principle I want to be able to specify that given some boolean multiple I want to append the multiple attribute or not. Below I've given a small example:

select (id := someId, name := someName, if (multiple) "multiple".attr := "")

This obviously won't compile, but it should convey my intent.

1

There are 1 answers

1
Ajay Padala On BEST ANSWER

You can try:

val attrList = if (multiple) List("multiple".attr = "") else List.empty
select (id := someId, name := someName)(attrList:_*)

This way its conditional whether you add that attribute or not.