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

257
Views
la ventana de solicitud envía el formulario sin importar si se comprueba si no

He integrado una ventana de confirmación en mi formulario Symfony con la función javascript.

Esta es mi definición de formulario de inicio:

 {{ form_start(form, {'attr': {'role': 'form', 'id':'editForm'} } ) }}

Y en javascript:

 $('#editForm').on('submit', function (e) { e.preventDefault(); validateEditForm(); }); function validateEditForm() { var nameInput; nameInput = prompt('Please input name to confirm edit:'); var name = document.getElementById('edit_name').value; if (nameInput === name || Number(nameInput) === name) { $('#editForm').submit(); } else if (nameInput === null || nameInput === "") { alert('You must enter name to confirm!'); return false; } else { alert("Entered name and default name don't match!"); return false; }

Un caso no está funcionando.

Cuando ingreso el nombre correcto en el cuadro, Ingrese el nombre del espacio de trabajo para confirmar la edición: aparece nuevamente. Luego vuelvo a hacer clic en Aceptar y se envía el formulario. ¿Hay algún problema con mis verificaciones if else?

Editar: Intenté hacerlo en dos funciones separadas y usé e.preventDefault(); y el comportamiento era el mismo.

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

0

Cambio el método de validaciónEditar como booleano de retorno. En el evento de envío del formulario, el método validateEditForm decide si enviar el formulario o no.

 $('#editForm').on('submit', function (e) { if(!validateEditForm()) { e.preventDefault(); } }); function validateEditForm() { var nameInput; nameInput = prompt('Please input name to confirm edit:'); var name = document.getElementById('edit_name').value; if (nameInput === name || Number(nameInput) === name) { return true; } else if (nameInput === null || nameInput === "") { alert('You must enter name to confirm!'); return false; } else { alert("Entered name and default name don't match!"); return false; }
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!