Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,200 --> 00:00:03,550
Now we spent a lot of time
2
00:00:03,550 --> 00:00:05,110
on this state here
3
00:00:05,110 --> 00:00:07,170
and it showed a lot of alternatives
4
00:00:07,170 --> 00:00:08,670
but up to this point of course
5
00:00:08,670 --> 00:00:10,130
we're not doing too much
6
00:00:10,130 --> 00:00:11,630
with that state.
7
00:00:11,630 --> 00:00:13,890
That's what I wanna change now, though.
8
00:00:13,890 --> 00:00:15,540
Now I wanna make sure that
9
00:00:15,540 --> 00:00:17,000
this form can be submitted
10
00:00:17,000 --> 00:00:18,870
when this button is pressed
11
00:00:18,870 --> 00:00:19,895
and that then
12
00:00:19,895 --> 00:00:22,030
we basically gather
13
00:00:22,030 --> 00:00:24,694
these different state slices here
14
00:00:24,694 --> 00:00:27,740
and combine them into one object
15
00:00:27,740 --> 00:00:28,830
which for the moment
16
00:00:28,830 --> 00:00:30,530
is then just locked to the console
17
00:00:30,530 --> 00:00:31,450
but which we can use
18
00:00:31,450 --> 00:00:33,340
for different things later
19
00:00:34,430 --> 00:00:36,550
and therefore we wanna listen
20
00:00:36,550 --> 00:00:38,520
to the form being submitted.
21
00:00:38,520 --> 00:00:41,110
Now we could add a click listener here
22
00:00:41,110 --> 00:00:44,190
to this add expense button
23
00:00:44,190 --> 00:00:45,410
but this would not be
24
00:00:45,410 --> 00:00:47,720
the best way of listening here
25
00:00:47,720 --> 00:00:48,930
because indeed there is
26
00:00:48,930 --> 00:00:50,250
a default behavior
27
00:00:50,250 --> 00:00:51,800
built into the browser
28
00:00:51,800 --> 00:00:55,010
and built into forums on web pages.
29
00:00:55,010 --> 00:00:56,520
If a button,
30
00:00:56,520 --> 00:00:58,600
especially with type submit
31
00:00:58,600 --> 00:01:01,070
is pressed instead of a forum,
32
00:01:01,070 --> 00:01:03,010
this overall forum element
33
00:01:03,010 --> 00:01:04,519
will emit an event
34
00:01:04,519 --> 00:01:06,010
to which we can listen
35
00:01:06,010 --> 00:01:07,623
and that's the submit event.
36
00:01:08,500 --> 00:01:10,200
So it's on this forum
37
00:01:10,200 --> 00:01:13,100
where I wanna react to on submit
38
00:01:13,100 --> 00:01:15,830
and then execute some function
39
00:01:15,830 --> 00:01:18,123
whenever this forum is being submitted.
40
00:01:19,370 --> 00:01:21,390
Now that's a function I'll add here
41
00:01:21,390 --> 00:01:22,440
and I'll name it,
42
00:01:22,440 --> 00:01:25,723
submit handler like this,
43
00:01:26,680 --> 00:01:27,513
add that here,
44
00:01:27,513 --> 00:01:29,910
we just point at submit handler
45
00:01:29,910 --> 00:01:30,743
as we did it
46
00:01:30,743 --> 00:01:32,813
for all the arbor events as well.
47
00:01:35,350 --> 00:01:36,510
Now, the thing here
48
00:01:36,510 --> 00:01:38,380
is that I just set
49
00:01:38,380 --> 00:01:40,840
that this is a default browser behavior
50
00:01:40,840 --> 00:01:42,450
and unfortunately,
51
00:01:42,450 --> 00:01:45,258
a part of this default browser behavior
52
00:01:45,258 --> 00:01:48,680
is that if you do click this button,
53
00:01:48,680 --> 00:01:51,230
the page reloads because the browser
54
00:01:51,230 --> 00:01:54,110
actually automatically sends a request
55
00:01:54,110 --> 00:01:55,770
whenever a form is submitted
56
00:01:55,770 --> 00:01:56,900
to the server
57
00:01:56,900 --> 00:01:58,320
which is hosting this webpage.
58
00:01:58,320 --> 00:01:59,153
So in this case
59
00:01:59,153 --> 00:02:01,350
to this development server
60
00:02:01,350 --> 00:02:03,410
and that's not what we want here.
61
00:02:03,410 --> 00:02:05,380
Instead here, we wanna handle
62
00:02:05,380 --> 00:02:06,810
this form submission
63
00:02:06,810 --> 00:02:10,070
with Java script and manually collect
64
00:02:10,070 --> 00:02:11,260
and combine the data
65
00:02:11,260 --> 00:02:13,150
and do something with it.
66
00:02:13,150 --> 00:02:14,950
Thankfully we can disable
67
00:02:14,950 --> 00:02:17,590
or prevent this default behavior
68
00:02:17,590 --> 00:02:18,480
because we again
69
00:02:18,480 --> 00:02:20,190
get an event object here,
70
00:02:20,190 --> 00:02:21,810
automatically just as
71
00:02:21,810 --> 00:02:23,470
for the change events
72
00:02:23,470 --> 00:02:25,370
and on this object,
73
00:02:25,370 --> 00:02:29,313
we can call a prevent default method.
74
00:02:30,240 --> 00:02:32,320
This is built into JavaScript
75
00:02:32,320 --> 00:02:33,840
nothing reacts specific
76
00:02:33,840 --> 00:02:36,720
this default JavaScript behavior.
77
00:02:36,720 --> 00:02:38,263
We can prevent the default
78
00:02:38,263 --> 00:02:40,990
of this request being sent
79
00:02:40,990 --> 00:02:43,320
and since that request is not sent
80
00:02:43,320 --> 00:02:45,360
the page will now also not reload
81
00:02:45,360 --> 00:02:46,240
because we stay
82
00:02:46,240 --> 00:02:47,710
on the currently loaded page
83
00:02:47,710 --> 00:02:50,240
without sending any request anywhere
84
00:02:50,240 --> 00:02:52,370
and we can continue handling this
85
00:02:52,370 --> 00:02:53,773
with Java script.
86
00:02:55,540 --> 00:02:56,440
So they offer now
87
00:02:56,440 --> 00:02:58,170
we can create our
88
00:02:59,190 --> 00:03:02,360
let's say expense data object here
89
00:03:02,360 --> 00:03:03,460
and now we'll combine
90
00:03:03,460 --> 00:03:05,640
all that entered data.
91
00:03:05,640 --> 00:03:07,220
Of course, if you used this
92
00:03:07,220 --> 00:03:08,460
one state instead of
93
00:03:08,460 --> 00:03:09,820
free States approach
94
00:03:09,820 --> 00:03:12,930
you already have such a combined object
95
00:03:12,930 --> 00:03:14,230
but I don't have that here.
96
00:03:14,230 --> 00:03:15,370
So I will now create it
97
00:03:15,370 --> 00:03:17,270
once the form is submitted
98
00:03:17,270 --> 00:03:20,100
and simply add a title here
99
00:03:20,100 --> 00:03:22,210
and set this to the value stored
100
00:03:22,210 --> 00:03:24,560
in the entered title state,
101
00:03:24,560 --> 00:03:26,510
add an amount property
102
00:03:26,510 --> 00:03:28,890
and set this to entered amount
103
00:03:28,890 --> 00:03:30,850
and a date property
104
00:03:30,850 --> 00:03:33,930
and actually set this to a new date,
105
00:03:33,930 --> 00:03:35,240
constructing a new date
106
00:03:35,240 --> 00:03:37,340
with the built in date constructor
107
00:03:37,340 --> 00:03:38,400
to which then in turn
108
00:03:38,400 --> 00:03:40,360
I passed the entered date
109
00:03:40,360 --> 00:03:42,280
which will parse that date string
110
00:03:42,280 --> 00:03:44,363
and converted into a date object.
111
00:03:45,630 --> 00:03:47,420
Now these property names here,
112
00:03:47,420 --> 00:03:50,120
title, amount and date are up to you
113
00:03:50,120 --> 00:03:51,950
because this is your object.
114
00:03:51,950 --> 00:03:52,943
This year, of course
115
00:03:52,943 --> 00:03:54,950
entered title, entered amount
116
00:03:54,950 --> 00:03:56,200
and entered date
117
00:03:56,200 --> 00:03:59,040
points at these state variables
118
00:03:59,040 --> 00:03:59,933
so to say.
119
00:04:00,830 --> 00:04:03,130
If you used the combined approach
120
00:04:03,130 --> 00:04:04,160
you also might wanna
121
00:04:04,160 --> 00:04:06,020
remap the property names
122
00:04:06,020 --> 00:04:07,100
because later in the app,
123
00:04:07,100 --> 00:04:08,680
I will rely on having
124
00:04:08,680 --> 00:04:11,960
a title amount and date property name.
125
00:04:11,960 --> 00:04:12,810
So make sure that
126
00:04:12,810 --> 00:04:14,140
these property names exist
127
00:04:14,140 --> 00:04:15,650
and hold the correct value
128
00:04:16,620 --> 00:04:17,779
and then for the moment
129
00:04:17,779 --> 00:04:21,480
I will just console log expense data
130
00:04:22,800 --> 00:04:24,000
so that we can see that.
131
00:04:25,240 --> 00:04:27,290
Now, if we reload this
132
00:04:27,290 --> 00:04:30,390
and enter test and 1299
133
00:04:30,390 --> 00:04:32,260
and then pick some date here
134
00:04:32,260 --> 00:04:34,620
if I click add expense,
135
00:04:34,620 --> 00:04:35,680
that's looking good.
136
00:04:35,680 --> 00:04:36,660
We've got this object,
137
00:04:36,660 --> 00:04:38,713
which has all that data stored.
138
00:04:40,000 --> 00:04:41,600
So this now all the works
139
00:04:41,600 --> 00:04:42,920
and we are reacting
140
00:04:42,920 --> 00:04:45,070
to the form submission.
141
00:04:45,070 --> 00:04:48,240
Now, I also wanna clear the inputs
142
00:04:48,240 --> 00:04:50,280
to delete the entered values
143
00:04:50,280 --> 00:04:52,573
when that form is submitted.
9340
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.