Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.0.1 custom field constructor... Extra parameters?

I am new to the play framework and want to write my own twitter bootstrap field constructor, which includes the usage of the bootstrap icon-classes. To make this dynamic I need to pass the icon-class via extra parameter. Is that even possible? I tried the following and some other variations:

index.scala.html

@(loginForm: Form[Login])

@import helper._
@implicitFieldConstructor = @{ FieldConstructor(twitterBootstrapInput.render) } 
@main("Akquise") {

<div class="container row">
    <div class="span4 offset5">
        @form(routes.Application.login(), args = 'class -> "well"){
            <h3>Anmeldung</h3>
            <fieldset>
            @inputText(loginForm("username"), '_label -> "Nutzername", '_iconcls -> "icon-user")
            @inputPassword(loginForm("password"), '_label -> "Passwort", '_iconcls -> "icon-key")
            </fieldset>

            <button type="submit" class="btn btn-primary">Login</button>            
        }
    </div>
</div>

}

twitterBootstrapInput.scala.html

@(elements: helper.FieldElements)

@************************************************** 
* Generate input according twitter bootsrap rules *
**************************************************@
<label for="@elements.id">@elements.label</label>
<div class="input-prepend">
    <span class="add-on" style="margin-right:-5px;">
        <i class="@elements.iconcls icon-size"></i>
    </span>
    @elements.input
</div>

With these parameters the compiler throws this error:

value iconcls is not a member of views.html.helper.FieldElements

How can I pass other arguments if that doesn't work?

like image 643
Demnogonis Avatar asked Jun 26 '12 07:06

Demnogonis


1 Answers

You're passing the parameter in the right way. But the additional parameters are stored in @elements.args. So you have to use @elements.args.get('_iconcls) to read your parameter.

like image 183
Leonard Punt Avatar answered Nov 18 '22 10:11

Leonard Punt