0

I have two radio buttons, one for SBT and one for Gradle. How do I specify the text for the buttons in Scala.js? My code looks like this:

lazy val toolChoice = fieldset(
      legend("Build Tool"),
      input(`type`:="radio", name:="tool", value:="sbt", "SBT"),
      input(`type`:="radio", name:="tool", value:="gradle", "Gradle")
).render

I see the buttons, but not the text. What am I doing wrong?

sjrd
  • 21,805
  • 2
  • 61
  • 91
gknauth
  • 2,310
  • 2
  • 29
  • 44

1 Answers1

3

Radio buttons do not have text per se. You need to have a sibling element to display the text. Ideally a <label>, so that it is clickable. See for example https://stackoverflow.com/a/2350782/1829647

In Scalatags, I guess it would look like this:

lazy val toolChoice = fieldset(
    legend("Build Tool"),
    input(`type`:="radio", name:="tool", value:="sbt", id:="toolsbt"),
    label(`for`:="toolsbt", "sbt"),
    input(`type`:="radio", name:="tool", value:="gradle", id:="toolgradle"),
    label(`for`:="toolgradle", "Gradle")
).render
Community
  • 1
  • 1
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • I usually do it as `label(input(...), "text")`, but yeah -- you want a label associated with the input... – Justin du Coeur Oct 26 '16 at 20:23
  • This looks promising except id="toolsbt" is coming up "reassignment to val", pointing at id. – gknauth Oct 26 '16 at 20:25
  • @sjrd: I got it working. Change id= to id:= above and I'll accept your answer. Thanks! – gknauth Oct 26 '16 at 20:30
  • Yeah, it was a typo, but useful because of the error message it generated. I'm always on the lookout for patterns between error messages and solutions. – gknauth Oct 26 '16 at 20:34