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

253
Views
desde el envío después de preventDefault () cuando se usa reaccionar

Lo que estoy haciendo aquí es hacer clic en un enlace para verificar si todos los campos están completos si se completa el formulario de envío como de costumbre, de lo contrario, se mostrarán algunos errores. Pero, ¿cómo puedo continuar enviando un formulario normalmente después de usar e.preventdefault en reaccionar?

 var formComponent = React.createClass({ verifyFields: function (e) { e.preventDefault(); if (this.state.primaryGuestName && this.state.primaryGuestMobile) { // how can i continue with form submission here(not using xhr) } else { showErrors(); } }, render: function () { <form action={this.props.action} ref="booking_form" acceptCharset="UTF-8" method="post"> {form contents} <a href="" name="submit_details" onClick={this.verifyFields} className="btn-flat btn-large rd-button">Confirm Details</a> </form> } }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Para enviar el formulario explícitamente, debe llamar al método de submit()

Su función de verificar campos se convertiría en algo como esto.

 verifyFields: function (e) { e.preventDefault(); if (this.state.primaryGuestName && this.state.primaryGuestMobile) { // how can i continue with form submission here(not using xhr) document.getElementById('myForm').submit(); } else { showErrors(); } },
over 4 years ago · Santiago Trujillo Report

0

Llame a submit en el formulario.

 e.preventDefault(); if (this.state.primaryGuestName && this.state.primaryGuestMobile) { e.target.submit(); } else { showErrors(); } }
over 4 years ago · Santiago Trujillo Report

0

Realmente no debería consultar el dom para el formulario, en su lugar, use el evento onSubmit y un botón, entonces la implementación es mucho más clara:

 var formComponent = React.createClass({ submit: function(e) { if (!this.verifyFields()) { e.preventDefault(); showErrors(); return false; } // continue here.. return true; }, verifyFields: function () { return this.state.primaryGuestName && this.state.primaryGuestMobile; }, render: function () { return ( <form action={this.props.action} onSubmit={this.submit} acceptCharset="UTF-8" method="post"> {form contents} <button type="submit" className="btn-flat btn-large rd-button">Confirm Details</button> </form> ); } });
over 4 years ago · Santiago Trujillo 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!