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

171
Visualizações
I want to clear input datepicker value on clicking clear button in react

enter image description here

When the value is set using defaultValue prop it is clearing the field but, not when used value prop. package details import { TextField} from '@material-ui/core';

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

0

Provided you do not have the control marked required, the onChange should fire on clear, handing you an empty string.

We also need to handle that case properly. Testing the date for validity and rejecting invalid dates by setting it to null perhaps.

With that change, make sure formatDateAndTime correctly handles the case in which the date is null, and so returns an empty string.

<TextField
  type="datetime-local"
  value={formatDateAndTime(this.state.editedValue.startDateTime) }  
  onChange={(date: any) => {
    const selectedDate = new Date(date.target.value);
    const sanitizedDate = isNaN(selectedDate) ? null : selectedDate;
    this.setState((prevState) => ({
      editedValue: {  ...prevState.editedValue,  startDateTime: sanitizedDate }
    }));
  }}
 />
about 4 years ago · Juan Pablo Isaza Relatório

0

The issues is caused because of the required property in the component, I removed it and it started working fine. check this code codesandbox, try adding and removing required property and click on clear button

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