I am trying to grok the instructions given in the play 2 scala tutorial for form template helpers. I am getting stuck in the section "Writing your own field constructors". It gives a sample template (without saying what the name of the file should be):
@(elements: helper.FieldElements) <div class="@if(elements.hasErrors) {error}"> <label for="@elements.id">@elements.label</label> <div class="input"> @elements.input <span class="errors">@elements.errors.mkString(", ")</span> <span class="help">@elements.infos.mkString(", ")</span> </div> </div>
Then it shows this code:
object MyHelpers { implicit val myFields = FieldConstructor(myFieldConstructorTemplate.f) }
I am confused about how this is supposed to relate to the template. (eg, is the template file supposed to be called myFieldConstructorTemplate.scala.html?) I tried some variations on this without luck.
I'm new to both scala and Play, but I also know play 2 and its docs are new, so I'm not sure what incredibly obvious thing I'm missing.
thanks!
I've just had the same problem, I agree with you the documentation is not clear at all...
Possible error 1
not found: value FieldConstructor
It means that you haven't imported the helper with this instruction :
@import helper._
Possible error 2
not found: value implicitConstructor
It means that you are declaring the field constructor in the wrong place in your template (i.e. : in the @helper.form method). To fix this, I declared my field constructor just after my import instructions :
@import form._ @import helper._ @implicitConstructor = @{ FieldConstructor(foundation_field.render) }
(My foundation_field.scala.html file is in the views.form package).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With