Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,500 --> 00:00:02,400
Validate is ready to go.
2
00:00:02,570 --> 00:00:06,290
It's time to validate the input fields in this lecture.
3
00:00:06,360 --> 00:00:10,000
We're going to start using the components we registered previously.
4
00:00:10,430 --> 00:00:13,710
I'm using the model we've prepared in the previous section.
5
00:00:14,270 --> 00:00:18,280
There are two forms which are the login and registration forms.
6
00:00:18,710 --> 00:00:21,740
We're going to begin with validating the registration form.
7
00:00:22,010 --> 00:00:26,900
The form will have additional fields that normally wouldn't appear on a registration form.
8
00:00:27,350 --> 00:00:32,400
At the very least, you'll usually ask for the email, username and password.
9
00:00:32,780 --> 00:00:36,320
I decided to add additional fields for demonstration purposes.
10
00:00:36,620 --> 00:00:41,750
It'll give us the opportunity to look at how we would validate various types of input fields.
11
00:00:42,050 --> 00:00:48,860
Now that we have an overview of things, let's begin switch over to the editor inside the authentication
12
00:00:48,860 --> 00:00:51,500
component search for the registration form.
13
00:00:51,830 --> 00:00:55,370
There's a comment about the form that says registration form.
14
00:00:55,940 --> 00:01:00,840
If you want, you can fold the login form to better focus on the registration form.
15
00:01:01,130 --> 00:01:03,890
We won't be dealing with the login form for a while.
16
00:01:05,060 --> 00:01:11,320
The very first field in the form is for the name, it's a TextField with no unique attributes.
17
00:01:11,600 --> 00:01:14,680
The objective of this lecture is to validate this field.
18
00:01:14,960 --> 00:01:16,550
We're going to use one rule.
19
00:01:16,820 --> 00:01:19,390
We want to make the name a required field.
20
00:01:19,730 --> 00:01:25,970
There's already an HTML5 attribute called required that prevents a form from being submitted.
21
00:01:25,970 --> 00:01:30,080
If a field is left empty, that's an option, but we won't be using it.
22
00:01:30,380 --> 00:01:35,000
We'll want to use validate because it'll give us better control over the error.
23
00:01:35,660 --> 00:01:41,690
The first step is to replace the form element for the registration form with the V form component.
24
00:01:46,040 --> 00:01:52,700
The job of the V form component is to organize a set of validations in a form we'll be able to globally
25
00:01:52,700 --> 00:01:54,760
control the form with this component.
26
00:01:55,130 --> 00:02:01,550
It'll help us verify if every input field in the form is valid, the form component will generate a
27
00:02:01,550 --> 00:02:04,690
tag that will wrap the component by default.
28
00:02:04,700 --> 00:02:06,170
It'll use a form tag.
29
00:02:06,530 --> 00:02:11,300
This is why we can safely replace the form element with the V form component.
30
00:02:12,020 --> 00:02:16,510
The thing we want to validate specifically is the value from the input field.
31
00:02:16,880 --> 00:02:22,930
By default, VALIDATE doesn't perform validation on any of the elements placed inside it.
32
00:02:23,570 --> 00:02:27,650
We need to tell it which input should be validated explicitly.
33
00:02:28,400 --> 00:02:34,580
We can tell it by using the V field component we registered in the previous lecture will start with
34
00:02:34,580 --> 00:02:36,010
the input for the name.
35
00:02:36,200 --> 00:02:42,380
It's the first input in the form will change the input element with the V field component.
36
00:02:44,940 --> 00:02:52,340
The field component is responsible for validating a single input, it'll generate an input tag by default.
37
00:02:52,680 --> 00:02:56,130
It's safe to replace the input element with this component.
38
00:02:56,490 --> 00:03:01,800
If we want to override the element it generates, we can add an attribute called AS.
39
00:03:04,410 --> 00:03:08,830
The value for this attribute is the name of the tag we want the component to generate.
40
00:03:09,150 --> 00:03:14,760
For example, if we want to generate a select element, we can pass and select.
41
00:03:15,210 --> 00:03:17,670
The original tag was an input tag.
42
00:03:17,670 --> 00:03:19,700
So we'll remove this attribute.
43
00:03:19,920 --> 00:03:20,820
We don't need it.
44
00:03:21,420 --> 00:03:27,810
In the resource section of this lecture, I provide a link to the field component documentation page.
45
00:03:29,930 --> 00:03:35,840
If we scroll down, we'll come across a section called Properties, it's a list of properties we can
46
00:03:35,840 --> 00:03:38,450
add to the component to modify its behavior.
47
00:03:38,720 --> 00:03:44,720
On this list, you'll find a property called as the as property is the name of the tag.
48
00:03:44,720 --> 00:03:48,110
The component will output the default tag as input.
49
00:03:48,380 --> 00:03:53,750
It's always a good idea to check with the documentation of the libraries we're using to check what we'll
50
00:03:53,750 --> 00:03:54,380
get rendered.
51
00:03:54,950 --> 00:03:56,380
Let's go back to our editor.
52
00:03:56,630 --> 00:04:03,050
It's not documented, but any attributes you add to the component are automatically added to the element,
53
00:04:03,050 --> 00:04:04,520
the component outputs.
54
00:04:04,880 --> 00:04:10,370
As long as it's not an official property for the component, it's passively added to the element.
55
00:04:10,760 --> 00:04:15,060
We don't need to worry about reapplying the class attribute to the input.
56
00:04:15,740 --> 00:04:20,839
The next thing we can start doing is tell the validate how it should validate the input.
57
00:04:23,450 --> 00:04:26,070
There are four steps for validating the input.
58
00:04:26,390 --> 00:04:30,120
The first step is to replace the input with the field component.
59
00:04:30,350 --> 00:04:31,430
We already did that.
60
00:04:31,730 --> 00:04:37,640
The second step is to assign a name to the input we're going to be validating multiple inputs.
61
00:04:38,030 --> 00:04:41,470
Validate needs a way to identify each input.
62
00:04:41,810 --> 00:04:43,730
We'll look at how to do that in a moment.
63
00:04:44,060 --> 00:04:46,250
The third step is to add the rules.
64
00:04:46,490 --> 00:04:52,040
The rules refer to a list of criteria of value must meet for it to be considered valid.
65
00:04:52,460 --> 00:04:58,050
Lastly, we need a way to handle errors if the user's input does not pass any of the rules.
66
00:04:58,340 --> 00:05:03,260
It's important we give feedback to the user to let them know how they can fix their errors.
67
00:05:05,710 --> 00:05:12,700
We're back in the ed we're going to handle assigning a unique identifier to the input it'll help validate,
68
00:05:12,700 --> 00:05:19,270
understand our form better, we can add an identifier by adding the name attribute to the field component
69
00:05:19,600 --> 00:05:21,400
will set the name to name.
70
00:05:24,040 --> 00:05:27,280
We'll move on to the next step, which is to add some rules.
71
00:05:27,490 --> 00:05:30,460
We'll look at registering rules in the next lecture.
7483
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.