Skip to main content

Input this - input that, HTML5 new input types

We are used to inputting types like "submit", "radio" or "hidden" but these days there are more components that are so common that are part of almost every web framework out there no matter if it is in Java, Ruby, Python or any other language. I'll give a short overview of what is being added in HTML5. The current state of them is that well... they sort of work, basically not all of the features are supported in all the modern browsers or IE.
Opera seems to support most of them and they have some good initial look there.

Date selection related.

Many times you need to create or integrate some control that will be a date-time picker, I've done this way too often and I'm sure that you also have. But why should we do something like this, this should be part of HTML and we should just style it with CSS. HTML5 makes this very simple with the date input types.

<input type="datetime" />
<input type="datetime-local" />
<input type="date" />
<input type="week" />
<input type="time" />

Live example:





 

Emails, Phone and URL

Email validation example on Opera 12
Input type email on iOS
Why would you need input types for this, well first thing is validation that otherwise you would need to do with JavaScript on the client side.
You could also style with CSS using input type specific selectors like input[type=radio]. Best thing about the input types by far is that they are semantically correct so mobile phones open input type specific view on the keyboard.
  
  <form>
    <input name="email" type="email" pattern="[^ @]*@[^ @]*" value="" />
    <input id="url" type="url" />
    <input id="phone" type="tel" />
    <input type="submit" />
  </form>
 
Live example:
Input type phone on iOS






 

Color

Input type that results in color picker.

<input type="color" />




Isn't this what you always wanted? ... at least when it comes down to html input.

TL;DR version
NEW HTML5 input types, awesome!!! see demo


Related Links

Demos - http://mitemitreski.com/demo/html5/input.html
W3 input element spec - http://www.w3.org/TR/2011/WD-html5-20110525/the-input-element.html
Support test - http://www.quirksmode.org/html5/tests/inputs_dates.html
Mozzila developers article - https://developer.mozilla.org/en-US/docs/HTML/Element/Input
Web Platform page - http://docs.webplatform.org/wiki/html/elements/input/type/search

Popular posts from this blog

HTML 5 data-* attributes, how to use them and why

It is always tempting to add custom attributes in HTML so that you can use the data stored there to do X. But if you do that there is no way of knowing if your HTML attribute will not be overridden in the future and used for something else and additionally you will not be writing valid HTML markup that can pass HTML 5 validator and with that you can create some very bad side effects. That is why there is a spec in HTML 5 called custom data attributes that enable number of useful features.

You may go around and read the specs, but the basic idea is very simple, you can add any attribute that starts with "data-" and that attribute will be treated as non-visible data for that attribute. By non-visible I mean that it is not something that gets rendered to the client so it does not affect the layout or style of the page, but it is there in the HTML so in no way this is private.
So let's get right into it, the following snippet is a valid HTML5 markup

<div id="aweso…

Basic Authentication with RestTemplate

Spring Rest Templates are very good way of writing REST clients. By default they work with basic HTTP so if we need to use Basic Authorization we would need to init the rest template with custom HttpClient. This way the Rest Template will automatically use Basic Auth and append to the HTTP headers "Authorization: Basic BASE64ENCODED_USER_PASS".

HttpClient client = new HttpClient(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("USERNAME","PASS"); client.getState().setCredentials( new AuthScope("www.example.com", 9090, AuthScope.ANY_REALM), credentials); CommonsClientHttpRequestFactory commons = new CommonsClientHttpRequestFactory(client); RestTemplate template = new RestTemplate(commons); SomeObject result = template.getForObject( "http://www.example.com:9090/",SomeObject.class );

In EE application this would probably be managed by DI framework like Spring Core and only initialized once sin…

How to Not Hate JavaScript: Tips from the Frontline

This article was originally published on voxxed under, https://www.voxxed.com/blog/2014/11/how-to-not-hate-java-script-tips-from-the-frontline/


In my work assisting teams with JavaScript related problems, I’ve noticed some common issues. If you're experiencing frustrations with the language too, this article might be of some assistance. Disclaimer: a few of my tips might be obvious to some of you, but hopefully you’ll find at least some useful nuggets of information here! These pointers are especially useful when dealing with enterprise applications and CMS solutions. This is where we have our code, the CMS code, the code from that team nobody wants to mention...and, of course, all of them are loaded asynchronously.
The Debugger Statement
This is one of the most underused features when dealing with JavaScript, especially since it’s supported by the majority of browsers. The debugger statement was part of the first edition of ECMA Script so it's been here for quite some time.

F…