2

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>
}
terdong
  • 43
  • 5

2 Answers2

2

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().

pme
  • 14,156
  • 3
  • 52
  • 95
  • Thanks. But unfortunately I've been already doing it the same way as your first. And this makes me annoyed. – terdong Jan 03 '19 at 07:37
  • @terdong Me too;) so I switched to the 2. possibility. But of course if there is a more elegant solution I would also take it gladly;) – pme Jan 03 '19 at 08:20
  • yep. jQuery is convenient. But I think jQuery is too heavy. And it is a tendency not to use more and more. Therefore I haven't been using jQuery from this project. In conclusion, I can't help but wait for next solution. – terdong Jan 03 '19 at 11:40
0

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

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

singebete
  • 21
  • 3