Hello, I am discovering play (2.6.20) and currently trying to build a quite complex form (nested with litteraly dozens of inputs). I managed to implement the form the play way and to create some simple FieldConstructor for input text. However I struggle to create my own helper for radio inputs (the base inputRadioGroup helper does not match my needs). I took inspiration from
Here is the template for the helper (radioInput.scala.html) which is inspired from the base inputRadioGroup one:
@import views.html.helper.FieldElements
@import helper._
@import play.api.i18n._
@import views.html.helper._
@(elements: FieldElements, options: Seq[(String, String)], args: (Symbol, Any)*)(implicit handler: FieldConstructor, messages: play.api.i18n.MessagesProvider): play.twirl.api.HtmlFormat.Appendable
@input(elements.field, args:_*){(id, name, value, htmlArgs) =>
<div class="row mt-3" id="row-background-hover">
<div class="col-md-5">
<label id="description-input" for="@elements.args.get('name)">@elements.args.get('label)</label>
</div>
<div class="col-md-7">
@options.map { v =>
<div class="form-check form-check-inline pt-1">
<input type="radio" class="form-check-input" id="@v._1" value="@v._1" name="@elements.name" @if(v._1 == options.head._1) {
checked="checked"}>
<label class="form-check-label" for="@v._1">@v._2</label>
</div>
}
</div>
</div>
}
In my main template, I import the helper with:
@radioRow = @{
FieldConstructor(radioInput.f)
}
And plan to use it with:
@inputText(simulForm("nestingParent.input1"),
'options -> Seq("input1_1" -> "input1_1_name", "input1_2" -> "input1_2_name", "input1_3" -> "input1_3_name"),
'id -> "input1-id",
'name -> "input1-name",
'_label -> "input1-label)(handler = radioRow, messagesProvider: MessagesProvider)
I have a compilation error pointing at when I import FieldConstructor(radioInput.f) telling me that there is a type mismatch:
type mismatch;
found : play.api.data.Field => ((Seq[(String, String)], Array[(Symbol, Any)]) => (views.html.helper.FieldConstructor, play.api.i18n.MessagesProvider) => play.twirl.api.HtmlFormat.Appendable)
(which expands to) play.api.data.Field => ((Seq[(String, String)], Array[(Symbol, Any)]) => (views.html.helper.FieldConstructor, play.api.i18n.MessagesProvider) => play.twirl.api.Html)
required: views.html.helper.FieldElements => play.twirl.api.Html
in addition, I tried to simply copy paste the content of the base inputRadioGroup instead of my custom helper and still get the same type of compilation errof. I cannot find any resource on how to build a proper radio helper. What am I doing wrong?