Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
validation message not hiding automatically when input field fill correctly

i am new in react, and try to create mutliple step form using reactjs, Material-ui, in this form validation, and submit buttons work perfectly fine. but i have one issue with the code that, filed is empty and i try to go to second step, it troughs error, but when i fill that filed. error still shows. and then finally i click on next after filling it and come back to first step. it will disappear. i want that when i type in active error, error message automatically disappear.

DEMO is HERE

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should create a onChangeField function in MultiStepForm and set it as onChange in all you field. So you can validate if errors includes the field

MultiStepForm.js

const onChangeField = (fieldName, value) => {
    setFormData({ ...formData, [fieldName]: value });
    if (errors.includes(fieldName)) checkValidation(activeStep);
};

StepOne.js

<TextField
    required
    type="text"
    name="firstName"
    style={{ width: "100%", margin: "1rem 0" }}
    label="First Name"
    variant="outlined"
    value={formData.firstName}
    error={errors.includes("firstName")}
    onChange={(event) => onChangeField("firstName", event.target.value)}
/>

<TextField
    style={{ width: "100%", marginBottom: "1rem" }}
    label="Last Name"
    variant="outlined"
    name="lastName"
    required
    error={errors.includes("lastName")}
    type="text"
    value={formData.lastName}
    onChange={(event) => onChangeField("lastName", event.target.value)}
/>
<TextField
    style={{ width: "100%", marginBottom: "1rem" }}
    label="Email"
    variant="outlined"
    name="email"
    required
    error={errors.includes("email")}
    type="email"
    value={formData.email}
    onChange={(event) => onChangeField("email", event.target.value)}
/>

codesandbox hope it help!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda