1

I wrote a method in my Play Framework 2 scala template to generate date/time inputs. I can't figure out how to pass html args like _label into it though.

@dateField(field: Field, timeName: String)(implicit handler: FieldConstructor, lang: play.api.i18n.Lang) = {
    @input(field, '_showConstraints -> false) { (id, name, value, args) =>
        <input type="text" value="@value" name="@name" @toHtmlArgs(args)>
        <input type="text" value='@eventForm(timeName).value()' name="@timeName" />
    }
}

I would like to be able to call this to generate a field with no label:

@dateField(eventForm("event.endDate"), "event.endTime", '_label -> "")

What do I need to do for this to work?

Ben James
  • 121,135
  • 26
  • 193
  • 155
TomahawkPhant
  • 1,130
  • 4
  • 15
  • 33

1 Answers1

3

You have to define a vargs field. In Scala, this is denoted by an asterisk. See this answer for more details.

Your code would then look like this:

@dateField(field: Field, timeName: String, more: (Symbol, Any)*)(implicit handler: FieldConstructor, lang:  play.api.i18n.Lang) = {
  @input(field, ('_showConstraints -> false :: more.toList) : _*) { (id, name, value, args) =>
    <input type="text" value="" name="@name" @toHtmlArgs(args)>
  }
}
Community
  • 1
  • 1
Marius Soutier
  • 11,184
  • 1
  • 38
  • 48
  • This gives me an error at `:: more...` Here is the message: `type mismatch; found : List[(Symbol, Any)] required: (Symbol, Any) Note: implicit method implicitFieldConstructor is not applicable here because it comes after the application point and it lacks an explicit result type'` – TomahawkPhant Jan 21 '13 at 22:46
  • Really? For me this works. Did you copy-paste it? Your error suggests that the last part (`: _*`) is missing. – Marius Soutier Jan 21 '13 at 22:50