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

292
Visualizações
Why is my Yup validation to check if the endDate value is not before the startDate value is not working

I've got a couple of material ui date picker components wrapped around a Field component from Formik. I'm validating data with the following yup validation schema:

import { object, string, number, array, date, ref } from 'yup';
import emptyStringToNull from 'helpers/emptyStringToNull';

// yup schema for input validation
export const curriculaSchema = object({
  startDate: date().required(),
  endDate: date()
    .min(ref('startDate'), "End date can't be before Start Date")
    .required(),
  location: object({}),
  standardsSets: array(),
});

This is how I'm wrapping the

<Grid item xs={4} sx={{ marginTop: 1.5 }}>
  <Field
    name='startDate'
    component={DatePicker}
    label='Start Date'
    TextFieldProps={{ fullWidth: true }}
    disabled={!isEditing}
  />
</Grid>

<Grid item xs={4} sx={{ marginTop: 1.5 }}>
  <Field
    name='endDate'
    component={DatePicker}
    label='End Date'
    TextFieldProps={{ fullWidth: true }}
    disabled={!isEditing}
  />
</Grid>

The error occurs for me only when I change the date on the endDate field. The problem is that it will cause an error even if the startDate is in fact before the endDate. The error then goes away if the startDate field changes. But at that point I'm unable to submit the form.

I'm not sure what I'm doing wrong here. I've checked a few answers on SO, but all seem to have the same issue.

about 4 years ago · Juan Pablo Isaza
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