Hello,
I'm trying to define a tags which contains a custom attribute, aiming to implemente Dojo Toolkit on top of Scalatags.
<pre>
@JSExport
object ScalaJSExample {
@JSExport
def main(args: Array[String]): Unit = {
val container = g.document.getElementById("container")
container.innerHTML = render().toString()
}
private def render() =
dijit.select(name := "select1")(
option(value := "TN")("Tennessee"),
option(value := "VA")("Virginia"),
option(value := "WA")("Washington"),
option(value := "FL")("Florida"),
option(value := "CA")("California"))
}
object dijit {
val select = "select".tag[dom.HTMLSelectElement].apply(
dojo._type := "dijit/form/Select")
}
</pre>
Despite the code above works, it's not convenient.
I would like to move all logic and initialization of attributes to a class.
Then I would be able to define a simple tag which does not contain any logic.
Something like this below (which does not work!):
<pre>
@JSExport
object ScalaJSExample {
@JSExport
def main(args: Array[String]): Unit = {
val container = g.document.getElementById("container")
container.innerHTML = render().toString()
}
private def render() =
dijit.select(name := "select1", foo := "indeed")(
option(value := "TN")("Tennessee"),
option(value := "VA")("Virginia"),
option(value := "WA")("Washington"),
option(value := "FL")("Florida"),
option(value := "CA")("California"))
}
object dijit {
val select = "select".tag[DijitSelectElement]
}
class DijitSelectElement extends dom.HTMLSelectElement {
val `data-dojo-type` : String = "dijit/form/Select"
var foo: String = ???
}
</pre>
The code above presents two issues:
1. The attribute "foo" is not recognized;
2. The attribute `data-dojo-type` is not applied to the object. I have tried other ways to inject the attribute onto the object, like using function "transforms", calling function update and other alternatives I found in the source code of Scalatags, but I was not able to make it work.
Thoughts?
-- Thanks