Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,740 --> 00:00:05,570
In the last section, we were able to trigger some validation on our form state object any time user
2
00:00:05,570 --> 00:00:10,280
pressed the summit button, now that we are actually pulling off this validation, we need to make sure
3
00:00:10,280 --> 00:00:16,460
that once our form is valid, we actually have the ability to extract the values that a user has entered
4
00:00:16,460 --> 00:00:17,600
into these two inputs.
5
00:00:17,900 --> 00:00:24,020
So, for example, if I enter in an email and then click on submit, OK, well, it's great that I validated
6
00:00:24,020 --> 00:00:29,600
this, but now I need to actually reach into this field and get the value out of there so I can submit
7
00:00:29,600 --> 00:00:34,750
it to a server or, I don't know, print it out, do whatever I want to do with the actual value.
8
00:00:35,360 --> 00:00:39,920
So let's take a look at the documentation again and get a better idea of how we can pull a value out
9
00:00:39,920 --> 00:00:40,520
of a field.
10
00:00:41,820 --> 00:00:49,200
OK, so I'm going to, again, look at my form state class, so down here under the method section.
11
00:00:50,930 --> 00:00:57,200
I'm going to find my save method right here, so the save method is what we're going to use to attempt
12
00:00:57,200 --> 00:01:02,300
to look at every different field that is nested within this form and somehow pull a value out of it.
13
00:01:03,020 --> 00:01:08,030
Now, the downside to the save method is that it has the same issue that the validate function does
14
00:01:08,030 --> 00:01:10,750
and kind of a lack of documentation.
15
00:01:11,150 --> 00:01:13,460
So it says that it saves every form fields.
16
00:01:13,790 --> 00:01:14,690
OK, what's that mean?
17
00:01:14,720 --> 00:01:16,430
What does it mean to save a form field?
18
00:01:17,090 --> 00:01:18,410
Well, let's take a look at a diagram.
19
00:01:18,410 --> 00:01:21,710
It's going to give you a better idea of what the save method does for us.
20
00:01:23,230 --> 00:01:29,350
OK, so very similar diagram to what we had before, we have our form states we were calling previously
21
00:01:29,350 --> 00:01:33,940
the validate function and that found all the different text form fields that were nested underneath
22
00:01:33,940 --> 00:01:34,420
this form.
23
00:01:35,110 --> 00:01:37,090
So now we're saying that we've got this save thing.
24
00:01:37,420 --> 00:01:42,720
So any time we call the save method, a very similar process is going to occur as validate.
25
00:01:43,390 --> 00:01:50,290
So when we call save the form state is going to find every text form fields that is nested underneath
26
00:01:50,290 --> 00:01:50,830
this form.
27
00:01:51,340 --> 00:01:52,450
So it's going to find that one.
28
00:01:53,720 --> 00:01:54,710
And it's going to find that one.
29
00:01:56,450 --> 00:02:01,280
And I'm going to change the color on this just to make a little bit more visible and then on each of
30
00:02:01,280 --> 00:02:02,510
these text form fields.
31
00:02:04,190 --> 00:02:09,229
The former state object is going to look and see if we have passed in a named property to the constructor
32
00:02:09,229 --> 00:02:15,290
of the text form field called on saved on saved is going to be a function that gets invoked with the
33
00:02:15,290 --> 00:02:17,630
current value of the text form field.
34
00:02:17,960 --> 00:02:21,110
So just about identical to how the validator worked as well.
35
00:02:22,050 --> 00:02:28,380
When we call Save, find the text Renfield's, find the answer functions tied to each one and invoke
36
00:02:28,380 --> 00:02:30,350
them with the current value of the inputs.
37
00:02:30,810 --> 00:02:35,160
So inside of that function is where we're going to have the opportunity to take the current value of
38
00:02:35,160 --> 00:02:39,750
the form field and submit it or do something useful with it, essentially.
39
00:02:41,120 --> 00:02:45,410
OK, so let's flip back over to our editor and we're going to first begin by adding on these on safe
40
00:02:45,410 --> 00:02:47,930
properties to both of our text form fields.
41
00:02:49,870 --> 00:02:52,780
Yes, I'm going to first find my email field.
42
00:02:54,810 --> 00:02:58,380
And underneath my validator, I'm going to add on unsaved.
43
00:02:59,130 --> 00:03:03,150
So this is going to be a function that gets called with the current value.
44
00:03:04,840 --> 00:03:10,900
Of this field, it's going to be a tight string because, again, it is a text field and we'll refer
45
00:03:10,900 --> 00:03:12,630
to that argument as simply value.
46
00:03:13,240 --> 00:03:17,260
And then inside of here for right now, we'll just print out that value and make sure that we're actually
47
00:03:17,260 --> 00:03:19,180
getting the email out of the field.
48
00:03:20,510 --> 00:03:24,230
Then I'm going to scroll down to my password fields and I'll do the same exact thing.
49
00:03:24,800 --> 00:03:28,460
So underneath the validator name property allowed in on saved.
50
00:03:29,370 --> 00:03:35,270
Assign a function to it that's going to be called with a string that we will refer to as value and I'll
51
00:03:35,270 --> 00:03:37,400
just print out value.
52
00:03:39,030 --> 00:03:40,690
I forgot my karma on that one.
53
00:03:40,750 --> 00:03:43,150
Don't forget the comma after the on save function.
54
00:03:44,630 --> 00:03:49,570
All right, so now the last thing we have to do is actually call save on our form state objects.
55
00:03:50,030 --> 00:03:52,040
So down again inside of Simit button.
56
00:03:52,220 --> 00:03:54,590
Here's our unpressed function right now.
57
00:03:54,590 --> 00:03:58,400
We're just trying to validate the form, but now we want to validate the form.
58
00:03:58,790 --> 00:04:03,740
And if it is valid, then we want to attempt to call save on the form state.
59
00:04:04,840 --> 00:04:10,450
So in order to only call save, if the form is valid, I'm going to first remove the print statements
60
00:04:10,570 --> 00:04:11,200
we've got in here.
61
00:04:12,590 --> 00:04:18,110
I'm going to remove the semicolon at the end of the line and I'm going to wrap the validate call inside
62
00:04:18,110 --> 00:04:20,480
of a if statement like so.
63
00:04:21,850 --> 00:04:26,590
So now think about what's going to happen here whenever a user presses on, the button on press gets
64
00:04:26,590 --> 00:04:27,070
invoked.
65
00:04:28,160 --> 00:04:33,860
We're going to look at every field inside this form and we're going to attempt to validate it, if every
66
00:04:33,860 --> 00:04:37,550
form is valid, then the validate function will return.
67
00:04:37,550 --> 00:04:37,990
True.
68
00:04:38,210 --> 00:04:41,210
So we will enter into the body of the if statements.
69
00:04:42,150 --> 00:04:47,910
But if any value or any field is invalid, then the validate function is going to return false and we're
70
00:04:47,910 --> 00:04:49,840
going to skip over the statement entirely.
71
00:04:50,530 --> 00:04:56,610
So now inside of here is going to be the perfect location for you and I to call save on the form state
72
00:04:56,610 --> 00:05:00,540
object and attempt to print out the password.
73
00:05:01,900 --> 00:05:02,680
And the email.
74
00:05:03,930 --> 00:05:07,320
So now inside of our if statement will do form key current state.
75
00:05:07,800 --> 00:05:13,050
So again, this is our reference to our form state object and I'll call save on it.
76
00:05:15,190 --> 00:05:16,690
All right, time to test.
77
00:05:17,170 --> 00:05:17,800
Let's do this.
78
00:05:18,370 --> 00:05:20,350
I'm going to do a full refresh.
79
00:05:25,230 --> 00:05:32,100
Wait just a minute for that to go, and now I'm going to enter in some e-mail that is valid, so it
80
00:05:32,100 --> 00:05:38,220
needs to have the at Symbol and I'll put in at least four characters here and I'll click on Submit.
81
00:05:39,060 --> 00:05:44,730
Now, present the form is valid, so I successfully see my email and password printed out inside the
82
00:05:44,730 --> 00:05:45,150
terminal.
83
00:05:46,560 --> 00:05:46,980
But.
84
00:05:48,760 --> 00:05:53,560
If I make either of these fields invalid, it's now password only has one character, so that's not
85
00:05:53,560 --> 00:05:53,950
valid.
86
00:05:53,950 --> 00:05:58,600
And I click submit again, I don't see a console over here because the form is valid and it should not
87
00:05:58,600 --> 00:05:59,200
be saved.
88
00:05:59,680 --> 00:06:04,600
If I again add in enough characters and click on submit again, I'll see the council log over here again
89
00:06:04,840 --> 00:06:06,330
or the print statement, not console.
90
00:06:07,280 --> 00:06:07,740
All right.
91
00:06:07,750 --> 00:06:12,120
So we've got our values through the use of these on saved things.
92
00:06:12,910 --> 00:06:17,200
Now, it's definitely great that we're printing out the values, but we still don't really have the
93
00:06:17,200 --> 00:06:23,290
ability to kind of take both the email and the password and kind of combine them together and like send
94
00:06:23,290 --> 00:06:25,360
them off to some remote API or something like that.
95
00:06:25,660 --> 00:06:27,280
So we still have a tiny bit of work to do.
96
00:06:27,670 --> 00:06:30,520
Let's take a quick pause and finish this thing up in the next section.
9438
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.