All language subtitles for 005 Adding Basic Validation_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

So in this input here,

we might want to add some validation

so that, for example,

I can't submit this form when the input is empty.

Because then I would get two empty logs here,

and whilst we only have logs here, in most cases,

we would probably send that data to a server

and we don't wanna send empty data to the server.

Though I also already wanna say the client-side validation,

which we're doing here, where we validate in the browser,

isn't everything you should be doing.

If you have a real website, a real web application

which you're building, then validating in the browser

as we are about to add it here is great

for the user experience

because you give the user a direct feedback,

but you also always should validates the input

on the server, because this code here on the browser,

this can all be edited by your users.

I can dive into the source code

and changed this raw JavaScript code.

So this is not reliable.

It's just there for providing a good user experience.

It's not a security mechanism or anything like that.

And I have an article and video on that,

which you'll find attached,

which also might be helpful when it comes to JavaScript

in the browser and the security implications

of doing things in JavaScript in the browser.

But that's a side note.

Let's come back to how we could validate this.

How could we make sure that we, for example, show an error

and don't log the values to the console

if we try to submit an empty field?

Well, of course, we can go to the formSubmissionHandler,

and there we can add an if-check.

Here we can add an if-check and we can then simply check

if the enteredName,

and here I'll go with that state value now,

if that enteredName is empty maybe.

We also might want to call trim on that enteredName string

to remove any excess white space

at the beginning and end.

Now, of course, the exact validation logic you need

depends on the form input value you are expecting.

If it's just some name, you might be fine

with just checking that it's not empty;

for an email address,

you might wanna validate that it's a valid email.

But I wanna keep it simple here,

so I'm just checking for it being empty or not.

Now, if it is empty, if we have an empty string here,

then I don't want to continue with the next lines

of code.

Because here we are using the entered value,

and I don't want to do that if that value is empty.

Hence here, I wanna return,

which returns from this overall function

and therefore cancels the function execution.

Now, the rest of this function will not be executed.

So if we saved this and I reload to clear my log,

if I now hit Submit here, you see nothing gets added here,

not even empty console logs.

There's nothing here.

If I do enter something, though, we still see that,

so that's working.

But what we're not doing is

we're not showing the user feedback.

We're not showing the user that something went wrong.

Of course, users don't have the developer tools open.

So if I'm a user visiting this page and I click Submit,

I don't know if anything happened

or if my input here is invalid.

I might be able to guess that an empty input is invalid,

but I get no feedback from the app.

So that's why we might want to show some error feedback.

And we can, of course, implement such a functionality

with React as well.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.