2

As HTML forms can come in many different shapes, I'd like to understand how to create individually designed forms without creating input helpers for each case. All examples I could find deal with form helpers.

In my controller I've got something like this:

formWithErrors => BadRequest(views.html.formsamples.getform1(formWithErrors))

My view:

<div class="form-group@{if(form.error("age")) " has-error"}">
    <label for="exampleInputAge1" class="control-label">Age</label>
    <input type="text" class="form-control" name="age" id="exampleInputAge1" placeholder="Enter age">
    @if(form.error("age")) {
        <span class="help-block">(1) @form.error("age")</span>
        <span class="help-block">(2) @form.error("age").get.message</span>
        <span class="help-block">(3) @Messages(form.error("age").get.message, form.error("age").get.args)</span>
    }
</div>
@helper.inputText(form("age"))

The error output looks like this:

(1) FormError(age,error.max,WrappedArray(100))
(2) error.max
(3) Must be less or equal to WrappedArray(100)

Number (3) is as close as I can get, but it's still not the correct error message, because as I understand @Messages takes separate arguments required for the translation, whereas form.error("age").get.args provides the arguments as a WrappedArray.

When I use Play Framework's default input helper, the (first) error message is: Must be less or equal to 100

How can I get to this message including all arguments required to translate a full error message?

(The full view file can be found on GitHub.)

Nick
  • 2,576
  • 1
  • 23
  • 44

1 Answers1

2

To use an array (or similar collection) you can use the following:

def method(args:String *):Unit

method("one", "two")

method(Seq("one", "two"): _*)

This is the line in the source code of the play framework: Helpers.scala#27

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
  • So I just had to change `form.error("age").get.args` to `form.error("age").get.args: _*` and it worked. Cheers! – Nick Feb 05 '14 at 07:24