IntelliJ shows error using scalatags with boolean attributes

85 Views Asked by At

Does anyone now why IntelliJ is showing an error here even though sbt compiles and everything works correctly:

enter image description here

*Edit: "stopEnabled" is a Boolean.

As I understand, to not show an error here, I would have to write someting like this:

button(if(!stopEnabled) disabled else JsDom.Modifier.*nothing*)

Is there any way of solving this nicely?

2

There are 2 best solutions below

2
Justin du Coeur On BEST ANSWER

disabled is a nuisance -- IMO, they spec'ed it wrong from the beginning, and have never made it better.

Offhand, I would guess that Scalatags' frag() constructor is probably the easiest solution: that takes its parameters and wraps them as a single frag. I believe that works even if there are no parameters. So I think you could do:

div(
  if (stopEnabled)
    frag()
  else
    disabled := "disabled"
)
3
pme On

You can do it with a sequence:

import scalatags.JsDom.all._

val stopEnabled = true

val modifiers = if(stopEnabled) Nil else Seq(disabled)

div(
  button(modifiers)
)