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
{{ message }}
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
I'm using reactjs and the lib unform to handle the register form structure of my application. I needed to do a more complex structure with a dinamic input, then, i did a saparated component to make the code more organized, but when i did the validation with yup i noticed that the fields of the child component didn't receive the errors like i thought it would receive.
Result: just the field of the main component where have the Form component from unform have the validation error.
constCadastroAdvF3: React.FC=()=>{const{ addToast }=useToast();constformRef=useRef<FormHandles>(null);consthandleSubmit=useCallback(asyncdata=>{formRef.current?.setErrors({});try{// validationconstschema=Yup.object().shape({professionalDescription: Yup.string().required('Descrição profissional obrigatória').min(300,'A descrição profissional deve ter no mínimo 300 caracteres.'),// the following itens are inside the react component formationArea// and professionalExperience.institution: Yup.string().required('Instituição Obrigatória'),course: Yup.string().required('Curso Obrigatório'),from: Yup.string().required('Data Obrigatória'),until: Yup.string().required('Data Obrigatória'),role: Yup.string().required('Cargo Obrigatório'),business: Yup.string().required('Empresa/Instituição Obrigatória')});awaitschema.validate(data,{abortEarly: false});addToast({title: 'Informações registradas com sucesso.',type: 'success'});}catch(error){consterrors=getValidationErrors(error);formRef.current?.setErrors(errors);}},[addToast]);return(<Styled.Container><Styled.Content><Styled.Form><h3>Formulário</h3><Formref={formRef}onSubmit={data=>{handleSubmit(data);}}><TextAreaname="professionalDescription"label="Descrição Profissional"placeholder="Sua descrição profissional..."/><FormationArea/><ProfessionalExperience/><SuperButtontype="submit">Próximo</SuperButton></Form></Styled.Form></Styled.Content></Styled.Container>);};exportdefaultCadastroAdvF3;
And a example of the structure of the FormationArea component:
constFormationArea: React.FC=()=>{// ...return(<context.Providervalue={{handleRemoveFormationArea}}><Styled.Container><divclassName="header"><h3>Formação</h3><buttontype="button"onClick={handleAddFormationArea}>AdicionarInstituição</button></div>{formationAreaFields.map((formationAreaFields,index)=>{return<Itemkey={index}Pkey={index}/>;
})}</Styled.Container></context.Provider>);};// above the component that is rendered in the formation areaconstItem: React.FC<KeyComponentProp>=({ Pkey })=>{// ....return(<CourseAreasContext.Providervalue={{handleRemoveCourseArea,handleAddCourseArea}}><divclassName="item"><Scopepath={`formation[${Pkey}]`}>{/* <h4>Instituição</h4> */}<Styled.PersonalizedColumnsFormation><Inputlabel="Instituição"name="institution"placeholder="Instituição"/>{Pkey>0&&(<buttontype="button"onClick={()=>handleRemoveFormationArea(Pkey)}><TiTrashsize={23}/></button>)}</Styled.PersonalizedColumnsFormation>{CourseAreaFields.map((course,index)=>{return<DownScopeAreaskey={index}Pkey={index}/>;
})}</Scope></div></CourseAreasContext.Provider>);};exportdefaultFormationArea;
The text was updated successfully, but these errors were encountered:
davidtmiranda
changed the title
How to handle with input errors on child components?
How to handle with input errors on child components inside the Form?
Dec 23, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm using reactjs and the lib unform to handle the register form structure of my application. I needed to do a more complex structure with a dinamic input, then, i did a saparated component to make the code more organized, but when i did the validation with yup i noticed that the fields of the child component didn't receive the errors like i thought it would receive.
Result: just the field of the main component where have the Form component from unform have the validation error.
See the image
here the code of the main form structure:
And a example of the structure of the FormationArea component:
The text was updated successfully, but these errors were encountered: