aviks suggestion is working. Maybe you have not imported the template correctly.
I did it like this. First I created a customSelectField.scala.html in views/helper/
as avik suggested:
@(field: play.api.data.Field, options: Seq[(String,String)], args: (Symbol,Any)*)(implicit handler: FieldConstructor, lang: play.api.i18n.Lang)
@getAsTuple(x : Any) = @{
x match {
case (value: String, text: String) => (value, text)
case _ => ("-1", "Select")
}
}
@input(field, args:_*) { (id, name, value, htmlArgs) =>
<select id="@id" name="@name" @toHtmlArgs(htmlArgs)>
@args.toMap.get('_default).map { dv =>
<option class="blank" value="@getAsTuple(dv)._1">@getAsTuple(dv)._2</option>
}
@options.map { v =>
<option value="@v._1" @(if(value == Some(v._1)) "selected" else "")>@v._2</option>
}
</select>
}
and then in my template e.g index.scala.html where I want the select I do:
@import helper._
@helper.customSelectField(
field = proposeNewTimeForm("selectTime"),
options = times.get,
'_label -> "Category",
'_default -> ("-1" -> "-- Choose a category --"),
'_showConstraints -> false
)
Remember you should NOT do:
@implicitField = @{
FieldConstructor(helper.customSelectField.f)
}
because this will cause your error.
If you would like to format the html surrounding the select somehow you could do as I with
a customField.scala.html
in views/helper/:
@(elements: helper.FieldElements)
@elements.input
<span class="errors">@elements.errors.mkString(", ")</span>
<span class="help">@elements.infos.mkString(", ")</span>
and then in the top of index.scala.html
:
@import helper._
@implicitField = @{
FieldConstructor(helper.customField.f)
}
Hope this helps!