Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,930 --> 00:00:07,830
The name and the message values are actually even easier to validate because I can't make sure that
2
00:00:07,830 --> 00:00:12,390
you're spelling your name right or that you've put in the correct message because obviously I have no
3
00:00:12,390 --> 00:00:18,450
idea what either of those things will be but I can go ahead and validate that you put a value in there
4
00:00:18,450 --> 00:00:23,310
to just make sure that there's something there and that'll be good enough validation for me.
5
00:00:23,580 --> 00:00:30,600
But we're not actually going to put the error on the name or the message but what we can do instead
6
00:00:30,900 --> 00:00:37,020
is to change the validity of our Send Message button.
7
00:00:37,020 --> 00:00:44,850
So what we can do is our buttons have a disabled prop and so if I go ahead and save this as true you'll
8
00:00:44,850 --> 00:00:48,540
see the button is disabled is great out and I cannot click it.
9
00:00:48,990 --> 00:00:56,730
So if we go ahead and reset this to check to see whether or not we have errors in any of the above text
10
00:00:56,730 --> 00:01:02,730
fields well then we can return true for this and make sure that they can't go ahead and send a message
11
00:01:03,000 --> 00:01:05,070
unless all of the fields are valid.
12
00:01:05,370 --> 00:01:08,330
So this is an extra way of doing validation.
13
00:01:08,490 --> 00:01:12,900
And I think it works nicely here especially for the name and the message fields where we don't really
14
00:01:12,900 --> 00:01:23,040
need to display an actual error to the user but we can check to see if the name dot length is equal
15
00:01:23,070 --> 00:01:24,190
to zero.
16
00:01:24,210 --> 00:01:34,500
So if there's no name at all then this would return true or if the message down length is equal to zero.
17
00:01:34,680 --> 00:01:42,540
Well then we would return true as well because we don't want an empty message or if the phone helper
18
00:01:42,630 --> 00:01:46,220
dog length is not equal to zero.
19
00:01:46,230 --> 00:01:53,740
And this is the same check that we had used above then this would be true or if the email helper dog
20
00:01:53,760 --> 00:01:57,100
length is not equal to zero.
21
00:01:57,150 --> 00:02:00,240
Well then we would want to return true as well.
22
00:02:00,240 --> 00:02:07,770
So this makes sure that all four of our inputs are valid before we can even send the message.
23
00:02:07,770 --> 00:02:14,160
So if we go ahead and save this now it will refresh then you can see the button starts off as being
24
00:02:14,220 --> 00:02:16,050
greyed out and disabled.
25
00:02:16,050 --> 00:02:16,890
You can't press it.
26
00:02:17,250 --> 00:02:22,110
So if we go in and I type in a name and then an email
27
00:02:25,710 --> 00:02:31,930
and then a phone number you can see it still is not enabled.
28
00:02:31,930 --> 00:02:38,110
We still cannot press it until I go ahead and type in a message and as soon as I have a character in
29
00:02:38,110 --> 00:02:42,850
here to make that message not zero the button becomes possible.
30
00:02:42,850 --> 00:02:49,120
You can see if I put in a message here I'll go ahead and I mess up any of the other fields so I'd get
31
00:02:49,120 --> 00:02:50,340
rid of the name.
32
00:02:50,350 --> 00:02:52,150
Well now you can't send the message again.
33
00:02:52,170 --> 00:02:53,770
So you got to have a name.
34
00:02:53,980 --> 00:03:00,430
And then the email if we go ahead and make it an invalid e-mail that will no longer allow us to send
35
00:03:00,430 --> 00:03:06,220
the message as well as displaying the error and the same way that the phone if we go ahead and get rid
36
00:03:06,220 --> 00:03:09,650
of that you see it's invalid and we can no longer send a message.
37
00:03:09,730 --> 00:03:11,390
And here there's a space in there.
38
00:03:11,410 --> 00:03:17,470
Let's go and get rid of that and you can see as soon as all four of these values are valid then we can
39
00:03:17,470 --> 00:03:20,250
go ahead and press the send message button.
40
00:03:20,260 --> 00:03:27,100
So that's our layer of security and validation to make sure that the message cannot even be sent without
41
00:03:27,100 --> 00:03:30,730
the correct values being in place.
42
00:03:30,810 --> 00:03:36,570
The last thing I want to do real quick is go ahead and add links to these sections up here.
43
00:03:36,570 --> 00:03:42,120
The phone number and the email so that when you click them and you're on a mobile device or even on
44
00:03:42,120 --> 00:03:48,720
the browser here it will actually pop up and allow you to either call a number directly on your phone
45
00:03:49,020 --> 00:03:53,610
or open up your e-mail client and send the e-mail message automatically.
46
00:03:53,610 --> 00:03:58,920
So those are two things that people really like to see and makes it really easy for your mobile users
47
00:03:58,920 --> 00:04:00,450
to get in touch with you.
48
00:04:00,450 --> 00:04:07,440
So what we'll do is we'll scroll up here to where we have the typography wrapping our e-mail and we're
49
00:04:07,440 --> 00:04:16,860
going to wrap this in a tariff and set that equal to the string mailed to Colon and then the e-mail
50
00:04:16,860 --> 00:04:17,490
address.
51
00:04:17,490 --> 00:04:25,020
So Zachary at g mail dot com but then we can come and close this and then we'll need to add a closing
52
00:04:25,020 --> 00:04:27,240
slash a tag.
53
00:04:27,240 --> 00:04:27,960
All right.
54
00:04:27,960 --> 00:04:36,580
And then we can come up and we'll wrap our phone number in a Harith set equal to the string.
55
00:04:36,690 --> 00:04:47,880
Tell colon and then the phone numbers so 5 5 5 5 5 5 5 5 5 5 and then we'll go ahead and close this
56
00:04:48,240 --> 00:04:54,370
and then we can add our closing a tag loops don't need the airplane just to a.
57
00:04:54,420 --> 00:04:58,530
And now if we go ahead and save that you'll see the page refresh.
58
00:04:58,530 --> 00:05:01,520
But now they're actually styled as links.
59
00:05:01,540 --> 00:05:02,900
We definitely don't want that.
60
00:05:02,910 --> 00:05:14,190
So on our a tag go ahead and add a style of text decoration none and then color inherit and I'll make
61
00:05:14,190 --> 00:05:20,430
sure that it retains the blue color and get rid of that underline and let's go ahead and copy that whole
62
00:05:20,430 --> 00:05:25,050
style property and paste that onto the email.
63
00:05:25,050 --> 00:05:30,840
So save that and you can see now they are returned to normal but there are still links and if I go ahead
64
00:05:30,870 --> 00:05:36,180
and I click on this you can see it actually will set up to make a call.
65
00:05:36,330 --> 00:05:42,990
And then if I click on this it will go ahead and open up my email provider which on the Mac this is
66
00:05:42,990 --> 00:05:44,550
the built in mail app.
67
00:05:44,550 --> 00:05:51,960
And if you're on a mobile device that'll go ahead and it will open up the mobile e-mail app and automatically
68
00:05:51,960 --> 00:05:54,270
have these send e-mail in place.
69
00:05:54,270 --> 00:05:59,640
So those are two nice little extras that definitely make it work better and they look better on mobile
70
00:05:59,640 --> 00:06:05,370
devices and for all your devices in general and is definitely a cool little feature that people just
71
00:06:05,370 --> 00:06:10,410
expect to see when you and you see a phone number on the mobile site you just expect to be able to click
72
00:06:10,410 --> 00:06:12,200
it and be able to call it right there.
73
00:06:12,210 --> 00:06:13,920
So that's a nice little trick.
74
00:06:13,920 --> 00:06:22,290
All it takes is the a hair off with the Tel prefix for your hair if so tell colon and then your phone
75
00:06:22,290 --> 00:06:26,230
number and email the mail to call and your email.
76
00:06:26,250 --> 00:06:27,340
So that's it.
77
00:06:27,360 --> 00:06:29,960
And we've got our validation set up.
78
00:06:30,000 --> 00:06:36,540
It was a little bit of work but thankfully regex makes it really easy to test the value and all we really
79
00:06:36,540 --> 00:06:43,150
had to do was set up the system to make sure that our error helpers were set at the correct time.
80
00:06:43,230 --> 00:06:46,250
Which leads to our error states being true or false.
81
00:06:46,260 --> 00:06:51,420
And that's really all there is to validation with the material UI text field.
8859
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.