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:04,580
The next optimisation we'll work on is outputting multiple errors.
2
00:00:04,590 --> 00:00:09,320
So far we've been outputting a single error rather than all of them.
3
00:00:09,330 --> 00:00:12,700
This is so that we don't overwhelm the user with errors.
4
00:00:12,720 --> 00:00:14,730
It would clutter the form visually.
5
00:00:14,760 --> 00:00:20,820
However, in some cases you may want to output multiple errors for a specific input.
6
00:00:20,970 --> 00:00:23,680
An example of this would be the password field.
7
00:00:23,700 --> 00:00:27,210
I'm sure you've encountered a fair number of password fields.
8
00:00:27,240 --> 00:00:29,250
They vary with their own rules.
9
00:00:29,280 --> 00:00:35,700
Some examples would be requiring a minimum character length, using various characters or using numbers.
10
00:00:35,730 --> 00:00:38,610
This is so that the user has a strong password.
11
00:00:38,940 --> 00:00:43,170
It would be annoying to type out a password only to learn that it's missing something.
12
00:00:43,200 --> 00:00:46,020
It would be preferential to render every error.
13
00:00:46,050 --> 00:00:50,370
This will allow the user to adjust their password based on our rules.
14
00:00:50,610 --> 00:00:53,130
Keep in mind that this is just my opinion.
15
00:00:53,160 --> 00:00:56,410
There are different ways to tackle user experience.
16
00:00:56,430 --> 00:00:58,410
It depends on the app you're building.
17
00:00:58,440 --> 00:01:04,590
Regardless, I think this would be a good example of how to output multiple errors at once.
18
00:01:04,920 --> 00:01:08,250
Search for the password field if you haven't already.
19
00:01:10,620 --> 00:01:15,550
We're going to focus on the first field because the second field will match the first one.
20
00:01:15,570 --> 00:01:18,300
It's not required to repeat the rules.
21
00:01:18,300 --> 00:01:22,410
If the first input isn't valid, then neither is the second one.
22
00:01:22,830 --> 00:01:26,480
The validate implements a fast exit strategy.
23
00:01:26,490 --> 00:01:29,730
It's a strategy that will end the validation process.
24
00:01:29,730 --> 00:01:31,590
If a single rule is broken.
25
00:01:31,590 --> 00:01:34,660
If there are additional rules, they won't be checked.
26
00:01:34,680 --> 00:01:38,430
This results in fewer resources and faster feedback.
27
00:01:38,460 --> 00:01:42,680
This is why you'll only see one error at a time for an input.
28
00:01:42,690 --> 00:01:45,060
We'll want to override this strategy.
29
00:01:45,060 --> 00:01:51,720
If we want to output multiple errors on the field component, we're going to bind a property called
30
00:01:51,720 --> 00:01:52,590
Bails.
31
00:01:52,590 --> 00:01:54,300
We'll set it to false.
32
00:01:56,580 --> 00:02:02,160
The Bales property will tell the field component not to use the fast exit strategy.
33
00:02:02,190 --> 00:02:06,730
This means every rule will be checked, even if a previous rule was broken.
34
00:02:06,750 --> 00:02:12,600
It's important to bind the Bales property because we want the component to interpret the value as a
35
00:02:12,600 --> 00:02:14,250
false boolean value.
36
00:02:14,490 --> 00:02:17,170
The next step is to loop through the errors.
37
00:02:17,190 --> 00:02:19,590
Here's where a new problem arises.
38
00:02:19,620 --> 00:02:24,110
Currently, we're using the error message component to output the errors.
39
00:02:24,120 --> 00:02:31,500
However, it it'll only output one error at a time, even if the bales property is added to the component.
40
00:02:31,710 --> 00:02:38,220
We're going to need to customize the behavior of the field component if we want to output multiple errors.
41
00:02:38,250 --> 00:02:42,180
The field component has a slot we can take advantage of.
42
00:02:42,210 --> 00:02:46,690
It's the only way we'll be able to output multiple error messages.
43
00:02:46,710 --> 00:02:50,370
We're going to create an opening and closing field tag.
44
00:02:52,370 --> 00:02:57,020
Since we're going to add some content, we need to output the input tag.
45
00:02:57,290 --> 00:02:59,600
Validate will not do it for us.
46
00:02:59,630 --> 00:03:02,480
Inside will pass in an input tag.
47
00:03:04,570 --> 00:03:12,190
Well cut and paste the placeholder class and type attributes from the field component to the input tag.
48
00:03:23,910 --> 00:03:30,270
Next we need to tell validate which input should be validated inside the slot content.
49
00:03:30,300 --> 00:03:35,160
We're going to add the V slot directive to de structure the field property.
50
00:03:37,400 --> 00:03:42,980
The field property is an object with the features for adding validation to an input.
51
00:03:43,340 --> 00:03:47,270
We must add this property if we want to validate the input.
52
00:03:47,300 --> 00:03:53,270
Otherwise, the validate will not be able to perform validation on the password field.
53
00:03:53,300 --> 00:03:58,630
We can bind the property by adding the V bind directive to the input element.
54
00:03:58,640 --> 00:04:00,350
We'll set it to field.
55
00:04:02,540 --> 00:04:06,030
Next, we'll work on the error below the input.
56
00:04:06,050 --> 00:04:10,790
We're going to add a div tag with the class text read 600.
57
00:04:13,020 --> 00:04:17,310
We're using a div tag because we'll be outputting multiple errors.
58
00:04:17,339 --> 00:04:20,490
Each error should be placed on a separate line.
59
00:04:20,519 --> 00:04:25,210
The div tag will assure us of that from the v slot directive.
60
00:04:25,230 --> 00:04:28,680
We're going to structure an array called errors.
61
00:04:30,910 --> 00:04:35,530
The ER's array will contain a list of errors triggered by the input.
62
00:04:35,560 --> 00:04:42,580
It's important to understand that the array will only be available if we set the bails property to false.
63
00:04:42,610 --> 00:04:45,510
Otherwise, we'll always get one error.
64
00:04:45,520 --> 00:04:50,530
We can loop through this array to output the errors on the div tag.
65
00:04:50,530 --> 00:04:53,140
We'll add the v four directive.
66
00:04:55,310 --> 00:04:59,330
The expression will be the following error in errors.
67
00:05:01,570 --> 00:05:05,410
Inside the tags will output the error with an expression.
68
00:05:07,620 --> 00:05:08,850
One less thing.
69
00:05:08,850 --> 00:05:10,440
We'll need to add a key.
70
00:05:10,470 --> 00:05:15,000
We'll bind the key attribute to the error alias in the loop.
71
00:05:17,250 --> 00:05:21,710
This attribute isn't necessary, but view recommends we set it anyway.
72
00:05:21,720 --> 00:05:22,950
We're almost finished.
73
00:05:22,950 --> 00:05:26,170
The last step is to update the rules for the password.
74
00:05:26,190 --> 00:05:30,150
At the moment we don't have a pair of rules that will appear along each other.
75
00:05:30,150 --> 00:05:33,060
Scroll to the schema in the password field.
76
00:05:33,060 --> 00:05:35,340
Set the minimum rule to nine.
77
00:05:37,410 --> 00:05:40,950
Next set the excluded rule to password.
78
00:05:43,140 --> 00:05:48,310
Allowing users to set their password to password is not considered to be a safe practice.
79
00:05:48,330 --> 00:05:52,820
We should prevent users from using specific passwords during registration.
80
00:05:52,830 --> 00:05:53,850
We're finished.
81
00:05:53,880 --> 00:05:56,610
Save your changes and refresh the page.
82
00:05:58,780 --> 00:06:02,440
I'm going to type password into the password field.
83
00:06:04,530 --> 00:06:08,730
This input will cause the minimum and excluded rules to break.
84
00:06:09,720 --> 00:06:14,900
The messages are the same because Validate uses the same message for every rule.
85
00:06:14,910 --> 00:06:18,750
As long as you see multiple error messages, then you're good to go.
86
00:06:18,780 --> 00:06:22,230
We'll continue optimizing the form in the next lecture.
8312
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.