Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Start a free Basic trial
to watch this video
HTML5 Web Forms
29:59 with Estelle WeylHTML forms have been the bane of web developers for years. Not anymore! Newer form features provide for native date pickers, place holder text, pattern matching, required fields, auto focus, error handling, and providing for the RIGHT keyboard on smartphones, all without JavaScript. We’ll learn all about creating dynamic web forms with form validation without the use of JavaScript.
-
0:00
[MUSIC].
-
0:04
[APPLAUSE].
-
0:08
Thank you, so today's talk is on HTML5 web forms.
-
0:11
It's basically on the, mostly on the input element.
-
0:13
So, we're gonna have a half hour talk on one element.
-
0:18
But if you want to, the slides are always up.
-
0:21
And they are always updated.
-
0:22
They're at just remember my name.
-
0:24
My name is Estelle.
-
0:25
I'm the only engineer, I think, named Estelle in the world.
-
0:28
I'm not sure. They're might be another one, but
-
0:30
I've got my name on the GitHub.
-
0:32
And the forms talk is just slash forms.
-
0:34
But if you go to estelle.github.io there's about 30 talk talks on JavaScript,
-
0:39
HTML and CSS there, and mobile performance.
-
0:42
So this is a web form.
-
0:44
This is what my web form looked like in, or not my web form,
-
0:48
cuz it didn't have the Twitter handle back in 1999.
-
0:50
But this is what your average web form looked like back in 1995,
-
0:54
when the first browsers first came out.
-
0:57
They still look like that today.
-
0:59
By simply adding properties to the input type you can change it, and
-
1:04
make it look like this.
-
1:05
This is not a pretty form.
-
1:07
But it has a lot of features, including native validation.
-
1:11
Including a date picker, and there's no JavaScript in that form.
-
1:16
[BLANK_AUDIO].
-
1:20
Okay, so let's go on.
-
1:21
So, even if you are still supporting IE7, and you think, oh like,
-
1:27
I can't use this stuff, someone actually is still supporting IE7 in this room.
-
1:33
I will not name names, but I met them, and I'm sorry, and
-
1:36
I told them to look for another job.
-
1:37
[LAUGH].
-
1:41
>> So even if you're, you know, even, this is what your form will look like,
-
1:45
if you use HTML5 and if HTML5 browser it'll look like this.
-
1:50
The exact same form in Netscape 4.7 will look like this, except for one feature.
-
1:56
The submit button will actually be prettier in Netscape 4.7 then this
-
1:59
submit button.
-
2:01
But use it.
-
2:01
Because people are using mobile devices, and it gives you the right keyboard.
-
2:05
If you're on a dynamic keyboard,
-
2:06
you will get the telephone keypad if you use the tel input type.
-
2:10
You will get the .com and I assume maybe in the UK you get a .co.uk.
-
2:14
I'm not sure, I haven't.
-
2:15
>> Still .com.
-
2:16
>> Still .com?
-
2:17
Well that's because we're more important than you are.
-
2:19
>> [LAUGH].
-
2:21
>> Com is in the US. [LAUGH] I'm kidding, and
-
2:24
then the email has the little @ symbol right there and the period,
-
2:29
and it has a space which is kind of almost virtually useless, except for
-
2:35
it isn't and I'll show you why so, one other thing is you have UI.
-
2:41
So, this is the date picker on IOS and
-
2:44
these are some older images of error messages that are custom.
-
2:50
Those aren't the words, actually they are the words, except for
-
2:53
this is a custom error message.
-
2:55
Isn't that cool?
-
2:55
That wasn't actually from the browser vender.
-
2:58
So, in HTML version 1.0,
-
3:02
I probably, we had these input types, and now we have a bunch of other input types.
-
3:06
And I've crossed some out.
-
3:08
Because they're not actually an issue in all five spec, but
-
3:11
they're, some of them are supported.
-
3:12
So I'll cover those as well.
-
3:15
But what we already have with the HTML's
-
3:18
regular input type is we have input type file.
-
3:21
And this has been supported pretty well for a long time.
-
3:24
Which is using input type file you can actually on a mobile device grab your
-
3:28
camcorder, grab your camera, or grab your microphone if you put the accept audio,
-
3:33
video, or image with capture of camera, camcorder, or microphone.
-
3:38
So it's just a simple input type file that we've had all along.
-
3:41
And we've always had the accept attribute.
-
3:44
And we have these values, and it's been working since Safari 6 and Android 3.
-
3:49
So it's, it's been there for a while.
-
3:51
Why not use it?
-
3:54
Okay.
-
3:54
In HTML 4, we had a bunch of attributes.
-
3:58
Name, disabled, the reason I put a colon in front of disabled is because it is
-
4:02
actually a CSS, but you actually don't have to put a colon in front.
-
4:04
It was just a note to myself to tell you.
-
4:07
CSS also has features.
-
4:09
Disabled and checked is a pseudo-class or
-
4:11
are rather pseudo-classes that you can use.
-
4:15
So we have a bunch of attributes, and
-
4:19
now we have a bunch of new attributes, and I will cover these as well.
-
4:24
And then, we had the HTML form elements, and
-
4:28
we also now have data list, output, meter, progress and keygen.
-
4:31
And I will cover most of those, not all of those.
-
4:36
Labels.
-
4:37
I know this is an HTML 5 talk, but this is an HTML 1 discussion.
-
4:43
Labels.
-
4:43
Use them.
-
4:44
They make your site more accessible, and they improve you, I mean, they improve
-
4:48
usability not just for the screen reader, but this is a tiny little dot.
-
4:55
I can click there and it will toggle that, right?
-
4:58
Or here, or here, and it will give focus and then I can start typing.
-
5:04
So, let's talk a little bit about the label.
-
5:05
There's two different types of labels.
-
5:06
There's the implicit label and the explicit label.
-
5:09
The explicit label is the one above.
-
5:11
And you use the, the attribute four with the value, which is the ID of the input or
-
5:17
the form control, so it could be a selector, anything like that so
-
5:21
with the ID, the, the four attribute matches the ID of the form control.
-
5:28
That is what 99% of people use.
-
5:30
The reason, I think,
-
5:31
that no one uses the implicit label is there's less styling ability, but
-
5:35
because IE6 and IE7 had an implicit label bug, so we were like never use it.
-
5:40
We're not supporting IE6 and seven anymore, except for that one dude here.
-
5:46
So go ahead and use implicit either way.
-
5:51
Another cool feature about using explicit label is that label on the first page,
-
5:56
I didn't use a table.
-
5:58
I think 95% of forms that I see on the web use tables for layout.
-
6:04
This is my layout.
-
6:06
It's an unordered list, which is semantically what this is.
-
6:11
And that's what it created.
-
6:13
All I did was display save label,
-
6:16
display in-line blog with 250 pixels or preferably percentages or m's.
-
6:22
And it laid it out beautifully.
-
6:24
Two lines of code.
-
6:26
Okay, it's not beautiful, but it's close enough to beautiful.
-
6:28
For me and my design skills, that's actually beautiful.
-
6:33
Okay, so, in terms of HTML5 attributes,
-
6:35
we have the placeholder attribute, which is progressive enhancement.
-
6:39
If you don't serve it to IE8, IE9, that's okay.
-
6:42
It supports IE10, and you simply write placeholder, and
-
6:46
you put your placeholder text there.
-
6:50
I think you probably guys already know this one so
-
6:52
I'm going to not spend too much time on it.
-
6:54
Because the pattern attribute is actually much more interesting.
-
6:56
The pattern attribute is an attribute that is supported on any
-
7:01
form control that doesn't have a GUI.
-
7:03
Like the, like, no buttons.
-
7:05
But if you're using older versions that don't support the gooey,
-
7:10
it at least makes sure that you at least have the right valid information if it
-
7:14
supports validation.
-
7:14
And if your processor doesn't support validation, it allows you to easily do
-
7:18
a plug in simply putting the pa, pulling the pattern.
-
7:21
So, what is a pattern?
-
7:23
Here I have /w 639, which means six through nine months based characters.
-
7:31
So if I do one, two, three, it's pink right now cuz it's wrong.
-
7:35
Four, five.
-
7:36
When I hit six it's gonna get right.
-
7:37
Seven, eight, nine.
-
7:38
And if I add a zero, it's telling me just through CSS, that, that is invalid.
-
7:45
Browsers that support native validation will not allow this
-
7:48
to be submitted if it is required.
-
7:51
So that was pretty simple and let's go back down one and
-
7:54
if I put a space in here, it doesn't match it either
-
7:57
because that doesn't match the /w if you know your regular expressions.
-
8:01
So, in this case here, this is for Firefox.
-
8:08
And IE that don't support,
-
8:09
I think Firefox actually just finally started supporting color.
-
8:11
But its for IE that doesn't support color.
-
8:14
At least it has the right regular expression.
-
8:16
And so I could do a pound sign, one, two, three, four,
-
8:20
five, six and it is supported.
-
8:24
Okay, then there is the required attribute.
-
8:28
What does it do?
-
8:31
It makes your form control required.
-
8:33
And you can match it with with CSS.
-
8:35
You can either do :required, or use the attributes selector,
-
8:41
or also for things that are not required, you can do optional.
-
8:49
For things that are not required, a paragraph is not optional.
-
8:50
The only things that are optional and
-
8:53
required are formed, are elements that could be required.
-
8:58
Okay.
-
9:00
So I've been talking a little bit about CSS,
-
9:04
these are the UI features, or some of the UI features in in CSS.
-
9:10
We have default, which no one knows what that means.
-
9:13
It is, I mean no one other than the people who write the spec and so
-
9:17
I had a hard time, there's no blog posts on it I don't think.
-
9:20
I think it means the default radio button and check box, and select item.
-
9:25
So, something is by default selected when the page loads, then that matches default.
-
9:30
In my testing, that is what it matched.
-
9:32
Then there's valid and invalid.
-
9:34
So something that is valid is something that is required and has a value.
-
9:38
Or something that matches it's pattern.
-
9:40
Or something we're gonna learn in the various input types like email.
-
9:45
Is it a valid email?
-
9:46
If it's not a valid email, it's invalid.
-
9:47
If it is a valid email, it's valid.
-
9:50
In range and out of range have to do with the number when you have a minimum and
-
9:53
maximum value which I'll show you later on.
-
9:56
Required and optional I showed you already.
-
9:58
And you can also, if you don't remember those,
-
10:00
you can also just basically use attribute selectors.
-
10:03
Or you can negate using an attribute selector as well.
-
10:06
Mm, kay.
-
10:08
So what are some good features of using these CSS features?
-
10:12
I'm repeating myself.
-
10:14
Input request.
-
10:15
So here is an input and this is basically, the UI for
-
10:19
the website that goes with the book that I just launched today.
-
10:24
It's actually the second edition of the book that was already printed.
-
10:26
And what it is, is on an input we're going to put a background image.
-
10:32
If it's required, it will have a little required icon next to it.
-
10:36
When that, when it had focus it's over written.
-
10:41
If it's invalid, it has the invalid png,
-
10:44
which is a thumbs down, and when it's valid it has a thumbs up.
-
10:50
But only on focus, cuz there's nothing worst in terms of the UI of having big
-
10:55
red check marks x's next to everything that's wrong while a persons entry data.
-
11:02
So in this deck, from now on, I'm going to use a pink for
-
11:05
invalid, light green background for valid.
-
11:08
Even in the default state, which is ugly.
-
11:10
But I just wanna show you stuff.
-
11:12
And then I'm gonna have a big border that's red and a big border that's green.
-
11:15
Because those are really good colors for people that are color blind.
-
11:18
For required and optional.
-
11:20
There's one thing I just did want to note before, you know,
-
11:24
talking about, cuz you can style all you want, but
-
11:27
if you if you actually autofill, the browser does this to you.
-
11:34
So I'm gonna file a bug later on today, cuz I think this is hideously ugly, but
-
11:36
this is intentional.
-
11:37
And this only a web kit for the Safari, Opera, and Chrome.
-
11:43
So you can't put a background image,
-
11:44
you can't change the color of the text, and right now you can't change well,
-
11:49
the background color of the text, and no images.
-
11:53
It's supposed to be a feature.
-
11:54
I don't think its a feature.
-
11:56
Next attribute is autofocus.
-
11:59
So autofocus gives focus on the element,
-
12:02
the first element that has the autofocus attribute.
-
12:06
There there's a, a rule in the spec where there's one other type of
-
12:11
element that gets focus it's whichever, it has nothing to do with focus.
-
12:16
It has to do with something the browser does and I can't, I'm sorry,
-
12:21
I can't remember what it is right now, cuz of jet lag.
-
12:25
But basically, the first element that has the autofocus attribute gets focused.
-
12:30
This is the same thing that happens if you actually have an error on the page.
-
12:34
It will, when you run through it,
-
12:36
it will give focus to that even though you don't use the autofocus attribute.
-
12:41
Don't use the autofocus attribute.
-
12:43
The autofocus attribute is what breaks my deck every time my deck breaks.
-
12:47
And then I forget, and if you can tell, the previous button is off
-
12:50
the screen right now, that's because that broke my deck.
-
12:53
Cuz what it does is it gives focus to that element when the page loads and
-
12:57
it moves it off and tries to give it focus and then I'm giving it focus back and
-
13:02
it just gets confused.
-
13:03
That's not actually what the browser's doing,
-
13:05
but it is giving focus directly on page load to that element.
-
13:10
Which is really bad user experience.
-
13:14
When you have a form,
-
13:15
don't autofocus to the 17th element just because you think it's really important.
-
13:19
They'll still wanna read the top part of your page.
-
13:22
So yes, it's a property.
-
13:23
And no, don't use it, okay.
-
13:28
The form attribute is kind of interesting.
-
13:30
And it has a major quirk in it, too.
-
13:32
The form attribute allows you to put a form control anywhere on your page not
-
13:36
in a form.
-
13:36
So what you do is you put as the value of the form control the form attribute,
-
13:41
the ID of the form that you want it to be associated with.
-
13:44
So you, somewhere on your page, over here you have the I, your form
-
13:48
with an ID in it, and then somewhere over here you can have a form control.
-
13:53
You can even have that form control in a different form.
-
13:55
It will be submitted when that form is submitted.
-
13:58
The thing is it associates it with a form.
-
14:01
So if you have it present it will associate it with the ID that's in there.
-
14:07
So if, if it's within a form and you remove it.
-
14:11
So it's an empty string.
-
14:12
It will disassociate it from the form that its currently its parent, if it has one.
-
14:18
So if you use this, and
-
14:19
you dynamically remove it, you wanna actually do a remove attribute.
-
14:23
Because you wanna remove the form attribute, not just nullify it.
-
14:26
So that is that, I just saved you 12 hours of time right there with that one.
-
14:30
>> [LAUGH].
-
14:32
>> Okay.
-
14:33
The type attribute.
-
14:35
The type attribute is the most basic attribute.
-
14:37
It is the only required attribute, and it's not actually required because if you
-
14:40
omit it, it, the browser will basically put it in as the value of text.
-
14:43
[COUGH] And that's what we're gonna talk about cuz there's many other values.
-
14:49
So we'll, we'll cover that in a little bit, minute.
-
14:52
Just realize, if you're working on an old browser and you put the date attribute in,
-
14:56
and it doesn't understand date, it'll just give you a text box.
-
14:59
Which is perfectly fine cuz someone can enter a text,
-
15:02
the date in a text box, okay.
-
15:05
So these are the old types that we've always had.
-
15:08
Button, checkbox, file, hidden, image, password, radio, reset, submit, and text.
-
15:13
Please don't put the reset on your pages.
-
15:17
I have no clue why anyone would want one.
-
15:19
And if you do, don't put it where the submit button is.
-
15:24
Or don't put the word submit on it as a value either.
-
15:27
[LAUGH] Another good April Fools' joke, yeah, okay, so
-
15:33
another April Fools' joke is to do a transition star,
-
15:38
transition, zero 200 milliseconds.
-
15:43
So that everything that transitions on your page waits 200 milliseconds before
-
15:47
loading.
-
15:48
If you just wanna lose your job, that's a good April Fools' joke to pull.
-
15:52
>> [LAUGH].
-
15:53
>> Okay. So these are the new input types.
-
15:57
We have color, url, telephone, email, number, range, search, date and time.
-
16:01
There's four that are crossed out here, cuz originally we had 13 new input types,
-
16:07
then we had 12 because date time was deprecated.
-
16:11
And date, time, local month,
-
16:12
and week are actually currently supported in almost all browsers.
-
16:18
Datetime local might change just the name to date time,
-
16:20
instead of datetime local cuz it's easier to write.
-
16:22
So these are still at, they're still in the thought process.
-
16:27
They haven't been eliminated.
-
16:28
Their name might change.
-
16:29
But all the other ones made it into the HTML5 spec that was approved and
-
16:34
made the found, file recommendation in November, okay.
-
16:40
I'm going to cover an element before I cover the next input types cuz this
-
16:42
element is awesome.
-
16:43
It is the datalist.
-
16:45
It simply provides you, since no one can see it in the back row three options,
-
16:51
Standarddista, O'Reilly, or Evotech, which are these three right here.
-
16:56
So it's basically like a select, but instead of putting a selector around it,
-
17:01
around options, you put a datalist, and those are options that you can use to,
-
17:05
to auto fill, but you can still put any other value.
-
17:08
So if I start writing http, you see it's open and
-
17:13
then I start with an f and that's not there.
-
17:17
But, if I do an, www., it's gonna narrow it down to just one,
-
17:22
cuz that's still an option and then none.
-
17:26
So you can actually auto complete or
-
17:28
rather use HX to autopopulate your options and dynamically do stuff and
-
17:32
jQuery actually has a plug-in that does basically just this.
-
17:36
So this is kind of cool.
-
17:39
But I want to cover it now, because on, it doesn't just work on text.
-
17:44
It works on other options too and I want you to know that this is what's happening
-
17:49
in the background when I get to those.
-
17:52
Okay.
-
17:53
So we have type color, and type color when it works,
-
17:59
there it goes, allows your color options.
-
18:03
And there you go, I have the color picker.
-
18:05
It's the native color picker, whatever your OS uses,
-
18:07
that is what color will give you.
-
18:09
You can do a little bit of a place folder and a pattern for
-
18:16
older browsers that don't support it yet like IE.
-
18:23
You can put required for IE, there's no reason to put required for
-
18:28
any other browser, because by default you will get black, it will be #00000.
-
18:35
If you choose a name color, like you can with the crayons, I think, where is it?
-
18:40
Oh yeah, here.
-
18:41
Here it says green, right?
-
18:43
It will actually use the hexadecimal value.
-
18:45
So what's nice about this, everyone will be entering the, the same format,
-
18:49
which is lower case hexadecimal color.
-
18:51
The reason I want to introduce datalist before I got to this page, is because here
-
18:56
I'm offering to my users that I would like them to pick one of five shades of red.
-
19:04
So I used a datalist with five red colors.
-
19:07
They can still pick any color they want.
-
19:11
But by default they get the reds.
-
19:14
So that's datalist, native in the browser.
-
19:18
There's JavaScript makes this, this, this slide deck work.
-
19:20
But there's no JavaScript in any of the slides except for one slide and I'll show,
-
19:24
I'll let, I'll let you know when we get to that, okay.
-
19:28
Then we have type="url" and type="url" is basically an URL.
-
19:34
g: works or g://.
-
19:38
[BLANK_AUDIO]
-
19:43
[SOUND] So my computer kind of died last night and
-
19:47
I thought I had a backup, but it's not quite there yet,
-
19:52
okay, so g:// would be a protocol.
-
19:56
I think it's actually a g: I think, as long as you have a colon.
-
19:59
Or a, or colon slash slash.
-
20:00
Depending on the browser, it accepts it.
-
20:01
So, if you actually want a specific URL format, give it a red pattern as well.
-
20:07
And, it gives you the dot, the slash and the com, on the phone.
-
20:10
Type tel gives you the phone keypad.
-
20:14
No validation but you can use a pattern.
-
20:18
And preferably this bottom one is better usability.
-
20:22
You put in like how you want the digits separated, so you don't have to tell
-
20:25
people that they can use a parenthesis or plus or you know it allows them.
-
20:30
If you use this don't auto forward when they complete the third digit.
-
20:33
You're, you're UX designer will tell you to do that, but
-
20:37
it's actually a bad user experience for people who are using the keyboard because
-
20:40
they're used to finishing and tabbing to get to the next box.
-
20:42
And then they'll tab out of the box, and
-
20:44
then they'll have to figure out how to go back.
-
20:45
[BLANK_AUDIO]
-
20:47
Type email.
-
20:50
Let's hope this works, e at g is now correct.
-
20:53
Cause that could be on an intranet, dot com.
-
20:57
Dot com.
-
20:59
This one has the multiple attribute.
-
21:01
So, I do comma, optional space, t at fu, or g, and that works.
-
21:08
So, it does not support the semicolon like Outlook, it supports the comma.
-
21:13
But you have native email validation.
-
21:17
No JavaScript and no regular expression this one.
-
21:20
If you wanted it to match a certain way,
-
21:22
you could actually put a pattern, and you get the right keyboard.
-
21:25
Input type number gives you a spinner.
-
21:31
Note that the increment, by default, is one.
-
21:36
There are three attributes, min, max and step.
-
21:41
Min is the minimum value.
-
21:42
Max is the maximum value.
-
21:44
And step is the step that it's gonna go up.
-
21:47
So, that was, that's why this one went up by 40 and this one went up by one.
-
21:52
One is the default.
-
21:54
If you actually put 10.2, that is an error.
-
21:58
There is no step in there, but that is an error,
-
22:01
because step equals 1 is actually basically added in there for you.
-
22:06
If you want to allow a float, step of any allows it.
-
22:11
Right?
-
22:14
And this just says it's wrong because this is supposed to be a negative number.
-
22:16
I forgot that next was zero.
-
22:18
Okay then we have type range, again with min, max and step.
-
22:28
So many people ask me this so I have a slide on it, how do you make it vertical?
-
22:35
Depends on the browser.
-
22:36
I'll cover that in a minute cuz for some reason I covered this first.
-
22:39
Oh, now I remember why.
-
22:41
Datalist.
-
22:43
You probably can't see it but
-
22:45
if you're sitting where I am, there's four little checks right there.
-
22:50
jQuery doesn't do this I don't think.
-
22:54
So you can actually give it a data list of this is where, you know, indicate to
-
22:58
user that you want them to go in that direction with six seven, eight and nine.
-
23:02
And here, the number, same number input type, I can either do that or I can
-
23:06
open my data list and give the options, options of seven, eight, nine and ten.
-
23:10
And seven, eight, nine, and ten were the options.
-
23:12
And look, I use the same data list twice.
-
23:14
You can use the same data list for
-
23:16
all of your, lists pra, attributes throughout the deck.
-
23:22
So, vertical ranges.
-
23:25
It's over here.
-
23:26
It's right there.
-
23:27
It's way there on the side of the screen.
-
23:29
I'll duck so you can see it.
-
23:32
Different browsers support, do it differently.
-
23:35
Firefox orient equals vertical.
-
23:37
Webkit or blink is -webkit-appearance, slider-vertical.
-
23:42
IE is writing-mode: bt-lr.
-
23:49
Dont worry about that, I know.
-
23:51
Cuz this, this line right here is the eventual solution,
-
23:55
which is a width that is narrower than its height.
-
23:58
It'll still follow like the longest of those two and that's the length it will be
-
24:03
but if the width is narrower than the height then it will be vertical.
-
24:08
Okay, then we have search which gives you, like,
-
24:11
this little UI feature of clearing it.
-
24:15
And basically it mimics the browser's search.
-
24:18
So in Safari, it's gray and is rounded but it doesn't do anything native.
-
24:26
Then we have the the date input types.
-
24:30
And so we have these type of controls.
-
24:32
You can use min, max, and step.
-
24:35
So you can pick every Tuesday by start,
-
24:36
by having your min as a Tuesday then everything else will be a Tuesday.
-
24:41
We have datetime-local which you have date and then time.
-
24:44
We recommend or, this, we, the royal we.
-
24:49
The W3C recommends that you actually put or
-
24:51
standards bodies recommend that you put, instead of using datetime,
-
24:54
that you use date and time as two separate entities.
-
24:58
Then there's a weird thing called week.
-
25:01
So week allows you to pick a week and
-
25:05
it will submit W-12- and then the year.
-
25:11
The first week of the year is the, is the one that holds January 4th.
-
25:17
So you might have three days of the year before in your first week or
-
25:20
you might have not, might not have the first, second,
-
25:24
and third in your week, in your, in week one.
-
25:28
And time.
-
25:29
Oh, I'll go on.
-
25:33
Okay. So what are useful dates?
-
25:36
The birthday might take a long time to spin through, but the way they did it now
-
25:41
with the actual three different features makes it much easier than it used to be.
-
25:44
You used to actually have to go through calendar and change years.
-
25:46
Time.
-
25:48
I like to do step of something.
-
25:51
The step of 900 is 15 times 60, which is 15 minutes.
-
25:54
So if you were to, gonna do an appointment time it's gonna be red until
-
25:59
2:00 p.m., because that is between 9:00 a.m and 5:00 p.m.
-
26:04
It's military time in terms of the attributes.
-
26:06
It's American style time in term, terms of the a.m., p.m.
-
26:11
Okay.
-
26:12
So these are the attributes that we have.
-
26:16
I haven't covered these so I'll cover these quickly.
-
26:18
These are actually, element,
-
26:21
attributes that you can put on a submit button or any type of button,
-
26:25
a button button, that will override the attributes that are in the form control.
-
26:29
So if someone is actually saving a, a form.
-
26:32
You can have it go you can have it
-
26:36
go to a different page instead of serving it right to the server.
-
26:40
Or you could say hey, you know, instead of submitting it do all sorts of things.
-
26:45
Then we have the validityObject, and
-
26:47
the validityObject is how you control the error message that you get.
-
26:52
By default,
-
26:53
if you have a title in your form control, the title will show when an error shows.
-
26:58
So that's already really cool cuz the title, when you hover over it,
-
27:00
it'll show, but it'll also be in the error message.
-
27:03
But you can write completely your own error message.
-
27:06
So we have value missing, which is when it's required, it's not there.
-
27:09
Tightness match, if you have a date and
-
27:12
you put just a simple number that's a typeMismatch.
-
27:14
PatternMismatch.
-
27:15
That's the regular expression pattern one.
-
27:18
TooLong is when it doesn't match the max length.
-
27:21
Underflow is lower than minimum.
-
27:23
Overflow is higher than maximum.
-
27:25
StepMismatch is when you have, when you forget to put step in and
-
27:29
it's not divisible by one.
-
27:30
Valid, don't know what that is.
-
27:36
Custom error is then an error that you can put in yourself.
-
27:39
So, let's look at a little bit of code, in one minute that I have left.
-
27:45
Here I set the custom validity on value missing to please enter an age.
-
27:50
If it's range underflow it's too low, overflow too high.
-
27:54
The most important thing to note is setCustomValidity
-
27:57
in the L statement as an empty string.
-
27:59
If not, when you set a CustomValidity message your form will never,
-
28:03
ever be valid.
-
28:04
It has to be fals.
-
28:06
So, nev-, always remember to put this as your L statement.
-
28:11
So. I was going to show you it in action but
-
28:17
I'll show you this version.
-
28:19
Here you can't read it, it says please fill out this field.
-
28:22
This error message is simply the contents of the title.
-
28:25
And I will show it to you.
-
28:29
Here, if I put 12 and I hit send, it says, you are too young.
-
28:36
So I wrote my own error message.
-
28:37
[BLANK_AUDIO]
-
28:41
Okay.
-
28:42
We have the meter element, it's yellow.
-
28:46
If it's outside of the min, of the low and the high.
-
28:49
But it will be between the min which will be the minimum number and
-
28:53
the max which is the highest number.
-
28:56
We have more meters.
-
28:58
I have two seconds left so I'll continue on to progress.
-
29:03
This is actually not what the progress bar looks like.
-
29:05
This is what the bug that the virus that took over my computer
-
29:08
yesterday did to my computer.
-
29:11
So that's not actually what the progress looks like.
-
29:12
But if you're interested in finding out more about the browser like
-
29:16
every single possible detail you could ever imagine about any of these,
-
29:21
I actually wrote this which is the HTML5 forms at WUFOO.
-
29:26
So if you do search on forms you usually end up here.
-
29:30
Not always, but it has ridiculous amounts of detail
-
29:35
on every single property and value.
-
29:39
Which browsers support it, which attributes pass,
-
29:42
which attributes fail, and every single corp that I talked about.
-
29:45
So if you don't remember what I said, I think there's a video,
-
29:48
but you can always go here.
-
29:49
So thank you very much.
-
29:50
[APPLAUSE].
-
29:52
[MUSIC]
-
29:55
>> [INAUDIBLE] and style.
-
29:56
I think there's so much packed into that.
You need to sign up for Treehouse in order to download course files.
Sign up