Writing your own field constructor


(Albaro Pereyra) #1

Hi I followed the guide here:
https://www.playframework.com/documentation/2.7.x/JavaFormHelpers

To write my own field constructor

<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>

It works great but instead of having the list of errors separated by a comma followed by a space, I’d like to break them up into new lines.

How can I accomplish this?

Please advise,

Thanks,


(Marcos Pereira) #2

Hi @AlbaroPereyra,

You can iterate over the errors as a regular collection:

https://www.playframework.com/documentation/2.7.x/JavaTemplates#Iterating

Best.


(Albaro Pereyra) #3

Fantastic!

<span class="error">
    @for(error <- elements.errors) {
      @error.format(messages())<br />
    }
</span>

This worked for me.

Thanks,