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

269
Visualizações
react + mui form onSubmit event not getting called

I am using the mui box react component with the component property set to form and an onSubmit set to the submit handler I need to trigger. I have a submit button at the end of the form. Whenever I click on the submit button it seems as if the form is submitting a get request as I see the form fields in the querystring but I am not seeing the submit handler get called. I added the e.preventDefault() in the handler and added a console.log and a debugger statement, none of which are ever reached. Also, the onChange handler I have on the textFields are not getting called either. What could be causing this to happen?

handler:

const submitForm = (e) => {
    e.preventDefault();
    console.log('We made it to the expected place.');
    debugger;
  }

Form:

<div>
        <div className="w-100">
          <Container>
            <h1 className="text-center">Login</h1>
            <Box className="card loginUI" component="form" autoComplete="off" onSubmit={submitForm}>
              <div className="card-body">
                <div className="formFlexContainer">
                  <div className="formInput">
                    <TextField className="w-100" id="userName" label="Username" variant="standard" name="userName" onChange={e => {console.log('text change 1'); setUsername(e.target.value)}}/>
                  </div>
                  <div className="formInput">
                    <TextField className="w-100" id="password" label="Password" variant="standard" name="password" onChange={e => {console.log('text change 2'); setPassword(e.target.value)}}/>
                  </div>
                  <div className="formInput d-flex justify-content-end">
                    <Button type="submit">
                      Login
                    </Button>
                  </div>
                </div>
              </div>
            </Box>
          </Container>
        </div>
      </div>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

you should add form tag in the parent element and and add onSubmit attribute to that ,

<form onSubmit={formik.handleSubmit}>
...
</form>

in this case , i used formik , but its not matter , you should add form , or you can delete type=submit from button and set onClick for button directly

about 4 years ago · Juan Pablo Isaza Relatório

0

I found the solution on this stackoverflow link: js events not firing in webpack built react application. The issue was an extra reference to the bundle.js file that webpack was already adding by default. Removed and the events began working.

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