Gandalf StormCrow
Gandalf StormCrow

Reputation: 26192

Play framework input without label

I've just started with Play Framework and I'm looking to create input field in scala template but without label and for some reason I'm unable to get rid of the generated label element. Here is how my code looks like :

@helper.inputText(form("name"), 'id -> "name", 'class -> "ui-state-default", 'autocomplete -> "off", 'placeholder -> "Please write name ...")

So I end up with this element along with my input (looking at browser source code) :

<dt><label for="s2id_autogen2">name</label></dt>

Is there any way of removing it?

Upvotes: 13

Views: 6923

Answers (3)

Gandalf StormCrow
Gandalf StormCrow

Reputation: 26192

My solution was :

@helper.inputText(form("name"), 
    'id -> "name",
    'class -> "ui-state-default",
    'autocomplete -> "off",
    'placeholder -> "Please write name ...",
    '_label -> null
)

Upvotes: 22

David Weinberg
David Weinberg

Reputation: 533

If you don't mind the label being in the generated source, you can generate an empty label by setting '_label -> "" If you don't want it in the DOM at all, you'll need to create a field constructor or hand generate the fields.

Upvotes: 0

Kris
Kris

Reputation: 5792

I guess you would need to write your own field constructor, eg:

@(elements: helper.FieldElements)

<div class="@if(elements.hasErrors) {error}">
    <div class="input">
        @elements.input
        <span class="errors">@elements.errors.mkString(", ")</span>
        <span class="help">@elements.infos.mkString(", ")</span> 
    </div>
</div>

More info here: http://www.playframework.com/documentation/2.0/JavaFormHelpers

Upvotes: 7

Related Questions