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.

14,408 thoughts on “Play Framework HTML5 input elements

  1. Howdy! This article couldn’t be written much better! Going through this post reminds me of my previous roommate!
    He always kept preaching about this. I most certainly will forward this article
    to him. Fairly certain he will have a very good read. Thank you for sharing!

  2. My programmer is trying to persuade me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using WordPress on a number of websites for
    about a year and am nervous about switching to another platform.
    I have heard excellent things about blogengine.net.
    Is there a way I can import all my wordpress posts into it?
    Any kind of help would be greatly appreciated!

  3. I really like looking through a post that will make men and women think.
    Also, thanks for permitting me to comment!

  4. It’s very trouble-free to find out any topic on net as compared to textbooks, as I
    found this piece of writing at this site.

  5. What a information of un-ambiguity and preserveness of precious
    knowledge regarding unexpected feelings.

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>