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

165
Visualizações
How to validate react select dropdown list without using hook

Can I validate my select dropdown without using react-hook, I have to ensure that the value in the select is never empty / null when user clicked onto the submit button.

handleChange = (option) => { this.setState({option:option.target.value})
<Select onChange={this.handleChange} value={this.state.option}>
<MenuItem>test1</MenuItem>
<MenuItem>test2</MenuItem>
</Select>

This is the current code for my react select, I would like to validate it so that the is never empty when clicking on submit button. As the code for my submit is just as below, along with basic buttons function etc..

OnClickSubmit(event)=>{event.preventDefault()}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can put a check on the OnClickSubmit method.

OnClickSubmit(event)=>{
   event.preventDefault()
   
   // check if value is not empty/null before invoking your fns
   if(!!this.state.option){
      // invoke your functions here
      ...
   }
   
}
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