Is it possible to return error message with customized field ? #11331
Unanswered
ArjunKarki
asked this question in
Q&A
Replies: 1 comment
-
Hi @ArjunKarki, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currenlty I have combined two field in one Controller phone and code and I put the object in controller name. and I have two Conroller like this, phone and alternative_phone.
Possible to return error message specifically for each one , currently message are overwrite and getting only second controller error.
<Controller
control={control}
name="user"
render={({field: {onChange, value, onBlur}}) => {
return (
<CountryCodePicker
mt={'$4'}
label={t('PhoneNumber')}
placeholder="8888 8888"
list={code_list}
phoneNumber={value?.phone}
onChangePhoneNumber={phNo =>
onChange({...value, phone: phNo})
}
selectedCountry={value.code}
onSelectCountry={country_code =>
onChange({...value, code: country_code})
}
onBlur={onBlur}
errorMessage={formState.errors?.user?.message}
/>
);
}}
rules={{
validate: ({phone}) => {
if (phone) {
return t('required', {
field: t('PhoneNumber1'),
});
}
},
}}
/>
<Controller
control={control}
name="user"
render={({field: {onChange, value, onBlur}}) => {
return (
<CountryCodePicker
mt={'$4'}
label={t('AlternativePhone')}
placeholder="8888 8888"
list={code_list}
phoneNumber={value?.alternative_phone}
onChangePhoneNumber={phNo =>
onChange({...value, alternative_phone: phNo})
}
selectedCountry={value.code}
onSelectCountry={country_code =>
onChange({...value, code: country_code})
}
onBlur={onBlur}
errorMessage={formState.errors?.user?.message}
/>
);
}}
rules={{
validate: ({alternative_phone}) => {
if (phoalternative_phonee) {
return t('required', {
field: t('PhoneNumber1'),
});
}
},
}}
/>
Beta Was this translation helpful? Give feedback.
All reactions