All language subtitles for 006 Providing Validation Feedback_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

To add some basic validation

we can manage more state.

We can add enteredNameIsValid state

and a setEnteredNameIsValid state updating function

which we get from useState.

And, here, we now want to start with false

so that initially the entered name is not valid.

And we can then set this to true

if the entered name is a valid.

So therefore here in the form submission handler,

if the input is invalid, then I want to set,

setEnteredNameIsValid to false because it is not valid here.

If we make it past this if check,

we can set enteredNameIsValid to true

because if we make it past this if check,

the value is valid.

And now we could use enteredNameIsValid

to show an error message.

Here below this input,

inside this form control div,

we could add a paragraph where we, for example,

say, "Name must not be empty."

And I only want to show this paragraph

if enteredNameIsValid is false.

So if it's not valid.

Now we of course learned

how we can show content conditionally in React.

And hence, here we can apply what we learned.

We can check if not,

hence the exclamation mark, enteredNameIsValid.

And if that's the case, we output this paragraph.

Otherwise we don't do anything.

And we can give this paragraph a class name

of error-text because that's one

of the predefined CSS classes I added here in index CSS

for some basic styling.

With that, I get this error

but now I also get this error before I even start typing.

So maybe we instead want to start

with setting this to true initially.

So that enteredNameIsValid is true initially.

With that, if I save here

we don't see the error message initially,

but if I click submit, it now shows up.

So this would be one way

of adding basic validation to this form and of making sure

that we give the users some feedback if things go wrong.

Now I actually prepared more validation feedback

which we can add

and that affects this CSS class

which is added on that div, that form control clause.

I'm not using CSS modules here

but old-school CSS classes which are set up globally

and then simply used here.

I did prepare a special invalid CSS class

which affects the input look, and therefore

I want to swap form control for form control and invalid,

if this input is invalid.

So here I could add a const nameInputClasses

and that depends on whether the enteredNameIsValid.

If that's true, then I want to add just form control

as a class.

Otherwise I want to add form-control

and invalid as classes.

And now a class name here is dynamic

and points at nameInputClasses.

NameInputClasses.

So these classes, which we're deriving here.

And with that, if I save this,

if I reload, we got this look.

If I submit this empty form, I got this look

which looks a bit better.

Now that is some perfectly fine validation

which you could add, but it has some downsides

at which I now want to take a closer look.

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