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.

19,007 thoughts on “Play Framework HTML5 input elements

  1. What’s Taking place i’m new to this, I stumbled upon this I
    have found It positively helpful and it has aided me out
    loads. I hope to give a contribution & assist other
    users like its helped me. Good job.

  2. I don’t know if it’s just me or if everyone else experiencing problems with your blog.

    It looks like some of the written text on your posts are running off the screen. Can somebody else please comment and let me know if this is
    happening to them too? This may be a problem with my internet browser
    because I’ve had this happen before. Many thanks

  3. I blog often and I genuinely thank you for
    your information. This great article has really peaked my
    interest. I’m going to take a note of your website and keep checking for new details about once a
    week. I opted in for your RSS feed as well.

    Feel free to surf to my blog post: BOBATOTO

  4. I’m amazed, I have to admit. Seldom do I come across a blog
    that’s both equally educative and engaging, and let
    me tell you, you have hit the nail on the head.
    The problem is something not enough folks are speaking intelligently about.
    I am very happy I stumbled across this during my search for something relating to this.

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>