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

577
Views
Confirme que los valores están configurados Sweet Alert (entrada múltiple) con Async

Estoy tratando de agregar validación a un modo de entrada múltiple que configuré con SweetAlert2.

Estoy usando el siguiente código, modificado de https://sweetalert2.github.io/#multiple-inputs

 jQuery('body').on('click', '#feedback', async function () { const {value: feedback} = await swal.fire ({ title: 'Send us your feedback!', showCancelButton: true, confirmButtonText: 'Submit', denyButtonText: 'Cancel', customClass: { content:'full-width' }, html: '<input id="ratingValue" type="text" />'+ '<input id="topicValue" type="text" />'+ '<input id="comment" type="text" />' , preConfirm: () => ({ rating: jQuery('#ratingValue').val(), topic: jQuery('#topicValue').val(), comment: jQuery('#comment').val() }) }).then((result) => { console.log(JSON.stringify(feedback)); if(feedback.rating != "" && feedback.topic != ""){ Swal.fire('Submitted!', '', 'success') } });

Obviamente, tengo un problema, estoy pasando el objeto de retroalimentación como un parámetro de promesa, por lo que no puedo intentar llamarlo desde el estado (entonces) ya que la variable aún no se ha inicializado y aparece un error. ¿Hay alguna solución para esto? Me gustaría validar mis entradas antes de enviarlas y poder permitir que el usuario se corrija a sí mismo.

¡Muchas gracias!

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

0

.on('click' toma una función de devolución de llamada, no devuelve una Promesa, por lo que no puede simplemente encadenarle .then() . Puede hacer algo como esto, supongo:

 jQuery('body').on('click', '#feedback', clickHandler); const clickHandler = async () => { const feedback = await swal.fire({...}); console.log(JSON.stringify(feedback)); if (feedback.rating != "" && feedback.topic != "") { Swal.fire('Submitted!', '', 'success') } }
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!