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

108
Views
Espere x0popup en la función javascript

Creé un código javascript que se supone que valida un formulario HTML. Durante esta validación se supone que hay una ventana emergente (en caso de que algo en el formulario no sea correcto).

Esto se ve así:

 function validateDisks() { var hiddenInput = document.getElementById('erasureHost'); if(hiddenInput.value == "") { x0p({ title: "Host is required", text: "Please choose a host from the host list.", type: 'warning', buttons: [{ type: 'warning', text: 'Ok' }] }).then(function(data) { return false; }); } var checkedBoxes = getCheckedBoxes("diskCheck"); if(checkedBoxes == null) { return false; } else if(checkedBoxes.length < 4) { x0p({ title: "Few disks", text: "You must select at least 4 disks for Erasure Coding", type: 'warning', buttons: [{ type: 'warning', text: 'Ok' }] }).then(function(data) { return false; }); } [...]

Mi problema es que cuando se ejecuta la función x0p, el script no espera el .then y simplemente continúa con la validación. Sin embargo, cuando ocurre un error, se supone que se debe informar al Usuario y luego no se debe enviar el formulario, lo que se puede lograr si la return false .

Ya he probado lo siguiente:

 async function validateDisks() { var hiddenInput = document.getElementById('erasureHost'); if(hiddenInput.value == "") { var x = await x0p({ [...] }).then(function(data) { return false; }); }

¿Cómo puedo asegurarme de que .then(function(data){ se ejecuta realmente y el script espera a que el usuario haga clic en el botón en la ventana emergente?

EDITAR: Creo que podría ser el problema que onsubmit="return validateDisks()" no esperaría las Promesas. Como he intentado validar solo la primera entrada ( hiddenInput ) y el formulario se envía antes de que pueda hacer clic en mi ventana emergente.

Tal vez la solución sea no enviar el formulario mediante action="diskChoice.php" sino enviar el formulario a través de JavaScript como action="validateDisks() y enviar el formulario con jQuery.

about 4 years ago · Juan Pablo Isaza
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!