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

175
Views
React/TS evita el envío de formularios al ingresar al usar la etiqueta "requerido"

Ya hay un montón de respuestas útiles para evitar el envío de formularios al ingresar ( ejemplo1 , ejemplo2 ). Sin embargo, ninguno de estos funciona si quiero incluir la etiqueta "requerido" en cualquiera de las entradas. Vea el código a continuación:

 const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); // do other stuff }; return ( <form id="LocationForm" onSubmit={handleSubmit} > <input type="text" placeholder="Please add country" onKeyUp={handleCountryChange} /> <input type="text" placeholder="Please add city" onKeyUp={handleCityChange} required /> <input type="submit" value="Submit" /> </form> )

Cuando presiono enter en la primera entrada, aparece un cuadro de diálogo que dice "Este campo es obligatorio". Idealmente, solo quiero que esto aparezca cuando hago clic en el botón Enviar y no cuando presiono Intro en cualquier otra entrada. Por supuesto, podría implementar esta lógica yo mismo sin usar las etiquetas requeridas, pero preferiría evitar reinventar la rueda aquí... a menos que haya alguna otra práctica estándar que la gente use. ¿Algún consejo?

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

0

Intente agregar onKeyPress={(e) => e.preventDefault() al <form>

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!