Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

575
Vistas
Confirm values are set Sweet Alert (multiple input) with Async

I am trying to add validation to a multiple-input modal I set up with SweetAlert2.

I am using the below code, modified from 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')
      }
  });

Obviously, I have a problem, I am passing the feedback object as a pass by promise parameter, so I can't try to call it from the (then) state as the variable hasn't been initialised yet and I get an error. Is there any workaround for this? I would like to validate my inputs before submitting, and be able to allow the user to correct himself.

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

.on('click' takes a callback function, it doesn't return a Promise, so you can't simply chain .then() to it. You can do something like this, I guess :

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda