Viewers: in countries Watching now:
In HTML5 First Look, author James Williamson introduces the newest HTML specification, providing a high-level overview of HTML5 in its current state, how it differs from HTML 4, the current level of support in various browsers and mobile devices, and how the specification might evolve in the future. Exercise files accompany the course.
The last form element that we're going to add to our rider review form is a date picker. It's very common to have a user choose a date or a range of dates when filling out certain types of forms. In the past, this has either been handled by a third-party plug-ins or libraries or by forcing text input fields conform to a specific formatting. If you've ever had to do that, you know that those methods are tricky at best. The HTML5 specification provides us with a date picker to make this process native to the browser.
Let's check that out. So I have the Trails file open in the 05_06 folder. I'm going to scroll down into my form again and just like we did with our riders, we're going to place this directly underneath the URL. So in-between writers and URL, I'm at about line 91, I'm going to add a new form input, but first I'm going to do a label for it. So we're going to go ahead and do the label tag. And this one is going to be for tripDate is going to be the name of this form element, so we're going to do that for tripDate.
And the label itself is going to just read the Date of trip. So let's go down to our next line and we're going to do our input form field. So we're just going to go ahead and do an input and inside this, I want to talk about the different types of input form fields that will allow us to do date pickers. So I'm just going to bring up my code ending here so we can see these and I'm going to talk about them individually. Now, the first one that you're going to run into is date and what date will do in supported devices currently will just give you a simple calendar.
Now, we also have month. So let me bring up that one and what month does is it'll display a simple calendar that also has a month pull-down menu. Yeah, in addition to month, you've got week and what week does is week gives you a calendar with a week pull-down menu. It's kind of an odd formatting, but it gives you sort of a third week in June type of pull-down. We also, I don't know if you noticed that when we did date, but we also have datetime and datetime-local. Let me talk about those two. Datetime gives you the calendar with a time picker on the top of it.
So if you want then to be able to choose a date and a specific time that they were posting something or a specific time they're going to set an appointment for, that'd be a really good one for that. Now, datetime-local is a calendar with a time picker with no time zone offset. Now, it displays exactly the same way as datetime and really the whole time zone offset thing is up to the user agent or device anyway. So its just gives you an ability to differentiate between the two of them. There is also one final one. There's one called time and what time does for you is it displays no calendar whatsoever.
It's just simply the actual time picker itself. Now, the specification itself is extremely vague about how devices and browsers should represent this data. It leaves it entirely up to the device to decide how much of a calendar you're going to have, which controls you're going to have. So the description I just gave you is kind of the way that the current browser that supports it, that Opera displays it, but it really might display totally differently in other devices or other browsers as this become supported. Okay, so what I'm going to do is I'm going to change my input type here to date.
I just want to do a very simple date. Now, inside that I am going to go ahead and give it the name of tripDate. Remember that's the name of this particular form element and we're going to repeat that process with id. We're going to do tripDate for that as well. Finally, we're going to go ahead and give it a tabindex of 50. So we're not setting any additional properties here whatsoever. We're just saying hey, this form element is a date form element. Now, I want to go ahead and save this and I'm going to test it in some other browsers first. I want to test it in Chrome and in Chrome, you can see that really we just get a text field.
So if the browser doesn't support the date input type, you're probably going to get a text field as a fallback. You'll notice that you get exactly the same thing in Safari, although we do get some exposed form controls. They're really not doing anything for us there. And we're getting sort of the same result in Firefox, just a text field. Okay, so hardly impressive., right? Well let's check out a browser that actually does support this. Okay, so here we are in Opera and I am going to scroll down a little bit to define the Date of our trip. Notice if I click this I get a nice little robust calendar control and I can cycle through the months.
Other browsers are displaying the date pickers as simple text inputs as we've seen and that might be satisfactory, but I'm going to guess it's not satisfactory if you're going to provide an alternate means of choosing days for those devices. So you're probably still going to need to include some type of fallback to a YUI calendar, or jQuery calendar, or some other type of the library widget. So as you can see these form controls have undergone a significant upgrade in HTML5. As support increases, elements in the specifications such as these date pickers as well as some unsupported elements that we didn't even see like color pickers for example.
They're in the specification, but nobody supports them currently. Those guys are going to allow the creation in more flexible and powerful forms within your applications. So really take a close look at the HTML5 specification and forms in preparation for what it's going to allow you to do as you're building forms within your own web sites and your own applications.
There are currently no FAQs about HTML5 First Look.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.