Months and years

While I was in San Francisco for the last Event Apart of the year in December, Luke pulled me aside while he was preparing for his A Day Apart workshop on mobile web design. As befits the man who literally wrote the book on web forms and also wrote the the book on mobile-first design, Luke was planning to spend plenty of time covering input on mobile devices and he wanted my opinion on one of the patterns he was going to mention.

Let’s say you’ve got your typical checkout form asking for credit card details. The user is going to need to specify the expiry date of their credit card, something that historically would have been done with select elements, like so:

With the introduction of the new input types in HTML5, we can now just use input type="month".

That’s particularly nice on mobile devices that support input type="month" like Mobile Safari since iOS5.

input type="month"

But the behaviour on non-supporting browsers would be to display just like input type="text" …not ideal for inputting a date.

So the pattern that Luke proposed was to start with the traditional double drop-downs for month and year, and then use feature detection to replace them with input type="month" in supporting browsers.

That was an angle I hadn’t thought of. Usually when I’m implementing new HTML5 input types (like input type="number") I put the new type in the markup and then try to come up with JavaScript polyfills for older non-supporting browsers. In this case though, the old-fashioned way is what goes in the markup and JavaScript does the enhancing for newer browsers.

The only downside is that some the desktop browsers that do support input type="month" do so in a way that—from a UI standpoint—seems like a step backwards from simply having two selects: Safari displays it with a spinner control like input type="number", while Opera shows an entire Calendar (days’n’all).

Anyway, I threw a quick hack together as a proof of concept so you can see it in action. I’m sure you can improve upon it. Feel free to do so.

Have you published a response to this? :

Previously on this day

9 years ago I wrote Landmark roles

Extending the semantics of HTML5 documents with some accessibility hooks.

10 years ago I wrote Huffcast

Read Write Huffduff Screencast Web

13 years ago I wrote New Year’s Resolution

Liquid layouts… no, wait, come back!

14 years ago I wrote By the time I get back from Phoenix

I’m back from Arizona and my nose is firmly pressed against the grindstone here in Brighton.

17 years ago I wrote Reading on the move

Now that I’m getting ready to head off to Arizona, I’m faced with the usual dilemma of choosing the right reading material for the trip.

17 years ago I wrote Surfing Safari

It looks like I made it back just in time to witness the birth of a browser. It’s a nifty little app from Apple called Safari.

18 years ago I wrote On the road again

The packing is just about all done and I’m ready to return to the somewhat milder climes of dear old Blighty.