Skip to content

Instantly share code, notes, and snippets.

@ochrons
Last active May 26, 2016 12:57
Show Gist options
  • Save ochrons/e04f3ef423b85ae41b35bc36af01552f to your computer and use it in GitHub Desktop.
Save ochrons/e04f3ef423b85ae41b35bc36af01552f to your computer and use it in GitHub Desktop.
// $FiddleDependency org.scala-js %%% scalajs-dom % 0.9.0
// $FiddleDependency com.lihaoyi %%% scalatags % 0.5.4
import scalatags.JsDom.all._
import org.scalajs.dom
import fiddle.Fiddle, Fiddle.println
import scalajs.js
object ScalaFiddle extends js.JSApp {
def main() = {
// $FiddleStart
val textbox = input(placeholder := "message").render
val result = div.render
textbox.onkeyup = (e: dom.Event) => {
result.textContent = textbox.value
}
val content = div(
h2("Hello Scala.js"),
textbox,
result
)
println(content)
// $FiddleEnd
}
}
// $FiddleDependency org.scala-js %%% scalajs-dom % 0.9.0
// $FiddleDependency com.lihaoyi %%% scalatags % 0.5.4
import scalatags.JsDom.all._
import org.scalajs.dom
import fiddle.Fiddle, Fiddle.println
import scalajs.js
object ScalaFiddle extends js.JSApp {
def main() = {
// $FiddleStart
val countries = Seq(
"Macau",
"Macedonia",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Mauritania",
"Mauritius",
"Mexico",
"Micronesia",
"Moldova",
"Monaco",
"Mongolia",
"Montenegro",
"Morocco",
"Mozambique"
)
val textbox = input(placeholder := "Country").render
val result = div.render
textbox.onkeyup = (e: dom.Event) => {
result.innerHTML = ""
result.appendChild(
ul(
countries
.filter(c => c.toLowerCase.startsWith(textbox.value.toLowerCase))
.map(t => li(t))
).render
)
}
val content = div(
h2("Hello Scala.js"),
textbox,
result
)
println(content)
// $FiddleEnd
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment