Search code examples
javatemplatesplayframeworktwirl

How create new Form object in template?


is possible to create new Form object via template? I need this because I don't want reapeat myself and use partial with fields from form. It looks like this:

@import play.i18n.Messages
@import play.i18n.Lang

@()

<div class="row">
    <div class="col-md-8 col-md-offset-2">
        <form class="form-horizontal" role="form" action="@routes.UserRegistrationController.completeUserProfile()" method="POST">
            @user._detailsForm(new Form[UserDetails])
        </form>
    </div>
</div>

and _detailsForm need param like:

@(form: Form[UserDetails])

regarding to documentation Form constructor need 4 param, but I have no idea hot to use it.

Passing Form[UserDetails] to my general template is my plan B, I am looking here other solution, thanks in advance.


Solution

  • this is a solution, special thanks for user7197

    @import play.i18n.Messages
    @import play.i18n.Lang
    @import play.data.Form
    
    @()
    
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <form class="form-horizontal" role="form" action="@routes.UserRegistrationController.completeUserProfile()" method="POST">
                        @user._detailsForm(Form.form(classOf[UserDetails]))
            </form>
        </div>
    </div>