Play Framework HTML5 input elements

The built in Play input elements are fairly restrictive in that you can’t specify the input type. I wrote a helper template that you can use to generate input elements which have HTML5 type attributes such as url, email, number, search etc. etc.

All you have to do is call the template method, passing the HTML input type as a parameter. For example:

@helper.html5.input(form("website"), '_label -> "Website:", 'type -> "url")

If you have a form field mapped as a play.api.data.Forms.email then the template will automatically infer it’s type so you don’t have to pass the type attribute in with your html attributes:

@helper.html5.input(form("email"), '_label -> "Email:")

If your field has the required constraint, e.g. it is a “nonEmptyText” then the template will add the HTML5 “required” attribute to the field as well.

You can get the source code here.

6,605 thoughts on “Play Framework HTML5 input elements

  1. I would like to thank you for the efforts you’ve put in writing this site.
    I really hope to check out the same high-grade content from you in the future as well.

    In fact, your creative writing abilities has encouraged me to get my own blog now ;)

  2. Otkrijte kvalitetne svjetiljke i rasvjetu za Vaš dom.

    Specijalizirana online trgovina za unutarnju i vanjsku rasvjetu
    – moderan dizajn, povoljne cijene i brza dostava.
    Svijet svjetiljki za Vašu kuću na jednom mjestu.

  3. I read this piece of writing completely about the difference of hottest
    and preceding technologies, it’s remarkable article.

  4. Hi there, I discovered your web site by the use of Google at the same time as searching
    for a comparable matter, your website came up, it
    seems to be good. I’ve bookmarked it in my google bookmarks.

    Hello there, just changed into aware of your blog through Google, and located that it’s truly informative.

    I am gonna be careful for brussels. I will appreciate if
    you continue this in future. A lot of people will be benefited out of
    your writing. Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>