These are chat archives for ThoughtWorksInc/Binding.scala

1st
Nov 2016
Milad Khajavi
@khajavi
Nov 01 2016 04:38

Hi @Atry
Here I have:

case class Todo(name: Var[String], score: Var[Int])

and inputTableRow like this:

  @dom
  def inputTableRow(todo: Todo): Binding[TableRow] = {
    tr(
      td(
        input(value := todo.name.bind,
          onkeyup := { e: Event => todo.name := e.srcElement.asInstanceOf[Input].value })
      ),
      td(
        input(value := todo.score.bind.toString,
          onkeyup := { e: Event => todo.score := e.srcElement.asInstanceOf[Input].value.toInt })
      )
    ).asInstanceOf[TableRow]
  }

when I open rendered file in browser, my browser show me these errors:

blob

What is the problem?!

Milad Khajavi
@khajavi
Nov 01 2016 05:05
I'm using Binding 10.0.0-M6 and Scalatags 0.6.1
杨博 (Yang Bo)
@Atry
Nov 01 2016 05:09
Try tr(...).render instead of asInstanceOf
Milad Khajavi
@khajavi
Nov 01 2016 19:38
thanks, my problem solved. but another one!
I want to convert this code to scalatag
<table>
  <tbody>
    {for (todo <- todos) yield {
    inputTableRow(todo).bind
  }}
  </tbody>
</table>.asInstanceOf[Table]
but scala tag version doesn't work:
  @dom
  def bindingTable(todos: BindingSeq[Todo]): Binding[Table] = {
    table(
      tbody(
        todos.map(inputTableRow(_)).bind.map(_.bind)
      )
    ).render
  }
blob
Milad Khajavi
@khajavi
Nov 01 2016 19:43
here is the definition of inputTableRow:
  @dom
  def inputTableRow(todo: Todo): Binding[TableRow] = {
    tr(
      td(
        input(value := todo.name.bind,
          onkeyup := { e: Event => todo.name := e.srcElement.asInstanceOf[Input].value })
      ),
      td(
        input(value := todo.score.bind.toString,
          onkeyup := { e: Event => todo.score := e.srcElement.asInstanceOf[Input].value.toInt })
      )
    ).render
  }