Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,150 --> 00:00:02,940
We're almost finished with validating the form.
2
00:00:02,969 --> 00:00:06,550
Each individual field has its rules applied to it.
3
00:00:06,570 --> 00:00:12,290
The next thing we'll want to do is validate the entire form if the user attempts to submit it.
4
00:00:12,300 --> 00:00:18,660
If the user attempts to submit an incomplete form, we will need to force validation on inputs before
5
00:00:18,660 --> 00:00:20,400
processing the request.
6
00:00:20,580 --> 00:00:26,520
The way the validate handles validation is by waiting for the inputs to be interacted with.
7
00:00:26,580 --> 00:00:30,270
It will not validate the moment the user lands on the page.
8
00:00:30,300 --> 00:00:35,970
We will need to force validation if the user doesn't trigger the validation on their own.
9
00:00:36,330 --> 00:00:40,650
The validate makes it extremely easy for a forcing validation.
10
00:00:40,680 --> 00:00:43,860
Open the authentication component in your editor.
11
00:00:43,950 --> 00:00:47,040
We're going to be focusing on the form component.
12
00:00:47,040 --> 00:00:50,490
We wrapped around the inputs on the form component.
13
00:00:50,490 --> 00:00:53,880
We'll add an event listener for the submit event.
14
00:00:56,120 --> 00:01:00,880
The summit event is slightly different from the submit event for a forum.
15
00:01:00,890 --> 00:01:04,940
The validate creates its own version of the Submit event.
16
00:01:04,980 --> 00:01:06,560
It'll do two things.
17
00:01:06,570 --> 00:01:12,260
First, it will force the field component placed inside it to perform validation.
18
00:01:12,290 --> 00:01:18,000
This enforcement includes inputs that haven't been touched, if any of the inputs are invalid.
19
00:01:18,020 --> 00:01:20,570
The event will not run the expression.
20
00:01:20,750 --> 00:01:24,840
Second, it'll prevent the page from refreshing upon submission.
21
00:01:24,860 --> 00:01:27,550
We don't need to add the prevent modifier.
22
00:01:27,560 --> 00:01:29,870
It's done for us behind the scenes.
23
00:01:30,050 --> 00:01:32,270
Let's add the function we want to run.
24
00:01:32,270 --> 00:01:36,260
If the forms are valid, we'll pass a new function called register.
25
00:01:38,480 --> 00:01:42,490
We never have to worry about manually checking if the forms are valid.
26
00:01:42,500 --> 00:01:47,000
The register function will not be called if any of the inputs are invalid.
27
00:01:47,030 --> 00:01:50,300
Any untouched fields will have their errors rendered.
28
00:01:50,330 --> 00:01:54,140
This will inform the user of what inputs they need to fix.
29
00:01:54,380 --> 00:01:57,590
The next thing we'll do is define the register function.
30
00:01:57,620 --> 00:02:02,540
Scrolling down will define the register function in the methods object.
31
00:02:04,790 --> 00:02:10,729
If the register function gets called, we know for sure that the values in the form are good to go.
32
00:02:10,759 --> 00:02:15,790
The submit event will provide our function with the values from the field components.
33
00:02:15,800 --> 00:02:17,240
The Root This section.
34
00:02:17,240 --> 00:02:22,070
We never used the the model directive to bind values to our inputs.
35
00:02:22,070 --> 00:02:26,090
It's not necessary to use the V model directive in our form.
36
00:02:26,420 --> 00:02:31,250
The validate comes with its own system for keeping track of the data in the form.
37
00:02:31,250 --> 00:02:34,520
This doesn't mean that the model directive isn't helpful.
38
00:02:34,520 --> 00:02:40,670
However, we don't need the V model directive since the library will keep track of the values for us
39
00:02:40,700 --> 00:02:46,190
inside the register functions parameters will add a parameter called values.
40
00:02:48,340 --> 00:02:50,770
Next, we'll log this parameter.
41
00:02:53,000 --> 00:02:56,620
This log will let us know if the validation was a success.
42
00:02:56,630 --> 00:02:58,130
Let's give this a test.
43
00:02:58,160 --> 00:03:00,320
Refresh the page on the browser.
44
00:03:01,830 --> 00:03:03,570
We want a clean slate.
45
00:03:03,600 --> 00:03:08,520
If you're using a browser that auto fills the input fields, then don't worry about it.
46
00:03:08,520 --> 00:03:09,780
Just empty them out.
47
00:03:09,780 --> 00:03:12,420
Submit the form without inputting anything.
48
00:03:14,760 --> 00:03:19,120
This submission will trigger an error in every field in the console.
49
00:03:19,140 --> 00:03:25,740
We won't see anything because the register function was not called the form component will not run the
50
00:03:25,740 --> 00:03:28,590
register function until the fields are valid.
51
00:03:28,710 --> 00:03:31,770
I'm going to fill up the form with valid values.
52
00:03:37,040 --> 00:03:41,970
If I were to submit the form again, we'd see our values logged in the console.
53
00:03:41,990 --> 00:03:42,980
This is great.
54
00:03:42,980 --> 00:03:45,950
We have a way to prevent the form from being submitted.
55
00:03:45,950 --> 00:03:50,360
If there are any broken rules, we can proceed with submitting the data.
56
00:03:50,810 --> 00:03:55,170
There are some additional optimizations we can make before submitting the data.
57
00:03:55,190 --> 00:04:00,830
We'll look at what else we can do to make the form more user friendly in the upcoming lectures.
5629
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.