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.

15,840 thoughts on “Play Framework HTML5 input elements

  1. Nice weblog right here! Also your web site so much
    up very fast! What host are you using? Can I am getting your affiliate link in your host?
    I want my website loaded up as quickly as yours lol

  2. Today, I went to the beach front with my kids. I found a sea shell and gave it
    to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear
    and screamed. There was a hermit crab inside and it pinched
    her ear. She never wants to go back! LoL I know this
    is totally off topic but I had to tell someone!

    my web-site :: mini midi keyboard

  3. Do you mind if I quote a couple of your articles as long
    as I provide credit and sources back to your webpage? My blog is in the exact
    same area of interest as yours and my users would genuinely benefit from a lot of the information you provide here.

    Please let me know if this alright with you. Thanks!

  4. I have been surfing online more than 3 hours today, but I never found
    any interesting article like yours. It is pretty price sufficient
    for me. Personally, if all website owners and bloggers
    made good content material as you probably did, the web will
    probably be much more useful than ever before.

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>