Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda