How do I create a custom field?

48 views
Skip to first unread message

Carlos De Matos

unread,
May 7, 2015, 8:18:18 AM5/7/15
to play-fr...@googlegroups.com
Looking at the console I spotted that the bootstrap helpers are being deprecated, so I tried to create my own helpers.

Off-course following the documentation suggestions (sorry, these are not instructions or guides - when I know what I am doing I will contribute to these :) ) did not get me anywhere. The documentation leaves much to be desired at this time.

I refer specifically in this case to the "Now create FieldConstructor somewhere..." statement.

  1. What is a somewhere? 
  2. Somewhere where? 
  3. On the view that needs the field? 
  4. Above the field? 
  5. As the last statement in the view? 
  6. As a parameter to the view? 
I tried options 3 and 4 above. Off-course, FieldConstructor is unresolved. So what do I need to import to resolve that and am I even moving in the right direction?

Yes this is a very good FREE open-source framework, but it is also a commercial enterprise. If you expect to have it grow, you need to improve the instructions of this to at least the quantity and quality of node.js standards.

Writing you own field constructor

Often you will need to write your own field constructor. Start by writing a template like:

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

Note: This is just a sample. You can make it as complicated as you need. You have also access to the original field using @elements.field.

Now create a FieldConstructor somewhere, using:

@implicitField = @{ FieldConstructor(myFieldConstructorTemplate.f) }

@inputText(myForm("username"))

alex s

unread,
May 7, 2015, 10:51:46 AM5/7/15
to play-fr...@googlegroups.com


четверг, 7 мая 2015 г., 15:18:18 UTC+3 пользователь Carlos De Matos написал:

I tried options 3 and 4 above. Off-course, FieldConstructor is unresolved. So what do I need to import to resolve that and am I even moving in the right direction?

import helper._
 
quantity and quality of node.js standards.

Are you suggesting deleting everything besides API docs?

Rick Bueker

unread,
May 7, 2015, 4:35:04 PM5/7/15
to play-fr...@googlegroups.com
If you want bootstrap try this: http://play-bootstrap3.herokuapp.com/
Reply all
Reply to author
Forward
0 new messages