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

147
Vistas
After onBlur the input is not accessible

I am using onBlur to change the state of the error, to validate the value in the input component. But as the user click away from the input, it takes a few seconds until he can click back the input to change the value.

Can anyone know why this happens? Another question,how can I change the type of the event returned from onBlur so not to be 'any'?

Form.tsx

  const [errorFlag, setErrorFlag] = useState(false);
  const [plz, setPLZ] = useState<string | undefined>(undefined);

  const onBlur = (e:any) => {
    setErrorFlag(e.target.checkValidity());
    };
      return (<Fragment>
          ...
          <Input 
            onChange={setPLZ}
            name="PLZ" 
            pattern="^[0-9]{5}$"
            errorMessage="* Invalid Postal Code"
            error={plz === ''} 
            required={true}
            onBlur={onBlur}  
            style={{ flexGrow: 0, width: '100px', marginRight: '20px' }}
          />
        </Fragment>)

FormInput.tsx

export interface InputProps {
  ...
  onChange?: (value: string) => void;
  onBlur?:(event: React.ChangeEvent<HTMLInputElement>) => void;
}

export class Input extends React.Component<InputProps, {
  value: string;
}> {

  constructor(props: InputProps) {
    super(props);
    this.state = { value: '' };
  }

  private onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    this.setState({ value: event.target.value });
    this.props.onChange?.(event.target.value);
   
  }
  private onBlur = (event: React.ChangeEvent<HTMLInputElement>) => {
    this.props.onBlur?.(event);
 }
  
  render() {

    return (
      <div key="form-name" className="formrow" style={{...this.props.style}}>
        <input 
          ... 
          onChange={this.onChange} 
          onBlur={this.onBlur}
          />
        <span id="formInput-errorspan" className="errorSpan">{this.props.errorMessage}</span>
      </div>
    );
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have not an idea for your first question, but you can use

<React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement> | undefined>

as type for your onBlur Event

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