How to fix the red mark that appears when using binding.scala in intellij?

216 Views Asked by At

I am developing with scalajs and binding.scala. I'm using the IDE as an Intellij. However, when using dom macro in Intellij, the following red mark appears. this error appears when I use the attribute value of id in the input element as macro What is the solution?

This error(a.k.a. "cannot resolve symbol something") appears when you use the id attribute value of the input element as marco.

please see the link of image below.

this is my code image.

 @dom
def render: xml.Elem = {
val name: _root_.com.thoughtworks.binding.Binding.Var[_root_.java.lang.String] = Var.apply("Binding.scala")
val show: _root_.com.thoughtworks.binding.Binding.Var[Boolean] = Var.apply(false)
<div>
  <p>
    <label for="showCheckbox">
      <input type="checkbox" id="showCheckbox" onchange={e: Event => show.value = showCheckbox.value }/>
      <span> Say hello to <input id="nameInput" value={name.value} oninput={_: Event => name.value = nameInput.value}/></span>
    </label>
  </p>
  {
  if (show.bind) {
    <p>
      Hello, {name.bind}!
    </p>
  } else {
    <!-- Don't show hello. -->
  }
  }
</div>
}
2

There are 2 best solutions below

3
pme On BEST ANSWER

I actually have the same problem. I have 2 ways dealing with it:

  1. Ignore these exception - as they are only a problem within IntellIJ (it compiles just fine).
  2. Use for example JQuery like this:

    import org.scalajs.jquery.jQuery 
    ..
    jQuery("#showCheckbox").value()
    

    As soon as your id gets more dynamic - you will need something like that anyway (at least that is what I know;)) -> jQuery(s"#${elem.id}").value().

0
singebete On

You could take advantage of the scalaJS Event passed in, maybe something like:

oninput={ev: Event => name.value = ev.target.asInstanceOf[HTMLInputElement].value}