You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To render an error message, it is good to check if the field was touched. For example, using bootstrap classes, we do something like:
<divclassName='form-group'><labelhtmlFor='email'>E-mail</label><Fieldname='email'placeholder='maria.silva@email.com'className={`form-control ${touched.email&&errors.email ? "is-invalid" : ""// Here's my check! <==}`}/><ErrorMessagecomponent='div'name='email'className='invalid-feedback'/></div>
And this works well in most cases, touched.email is yet undefined and JS is able to understand undefined as false. But it gets tricky when dealing with FieldArray.
The problem is when checking something like touched.email[index], well, undefined has no 'index' property. And it gets trickier when we have an array of objects, like touched.friends[index].name
I did some workarounds with try and catch blocks, but I believe that it is not the best option. Does the Formik have some proper way to deal with this?
And, a possible suggestion, isn't it a good idea to send false values when calling touched?
The text was updated successfully, but these errors were encountered:
❓Question
To render an error message, it is good to check if the field was touched. For example, using bootstrap classes, we do something like:
And this works well in most cases,
touched.email
is yetundefined
and JS is able to understandundefined
asfalse
. But it gets tricky when dealing with FieldArray.The problem is when checking something like
touched.email[index]
, well, undefined has no 'index' property. And it gets trickier when we have an array of objects, liketouched.friends[index].name
I did some workarounds with
try
andcatch
blocks, but I believe that it is not the best option. Does the Formik have some proper way to deal with this?And, a possible suggestion, isn't it a good idea to send
false
values when callingtouched?
The text was updated successfully, but these errors were encountered: