Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
MUI TextField: ¿Cómo evitar que se envíe el formulario?

Estoy creando un formulario usando React y MUI . Quiero evitar que se envíe el formulario cuando el usuario presiona la tecla Intro. Normalmente haría eso con e.preventDefault() , pero de alguna manera eso no funciona. Creo que tiene algo que ver con el componente TextField de MUI.

Aquí hay un ejemplo simple para mi formulario y aquí está

 function MyForm() { return ( <form onSubmit={(e) => { e.preventDefault() /* do submit stuff here */ }}> <TextField id="outlined-basic" label="Outlined" variant="outlined" /> <Button type='submit'>Submit</Button> </form> ); }

¿Estoy haciendo algo mal aquí?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La función preventDefault en onSubmit del formulario evita que la página se vuelva a cargar y, básicamente, debe escribir otro preventDefault dentro del campo de texto como se muestra a continuación:

 <TextField onKeyPress={e => e.key === 'Enter' && e.preventDefault()} />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!