Kavvson Empcraft
Kavvson Empcraft

Reputation: 443

Sweet Alerts - Queue form

Greetings I am wondering if its possible to get the input data from the - Chaining modals (queue) example. It returns only a generic array of values, would it be possible to get something like field name and value out of it? There are no solutions out there as Iam aware of.

swal.mixin({
  input: 'text',
  confirmButtonText: 'Next →',
  showCancelButton: true,
  progressSteps: ['1', '2', '3']
}).queue([
  {
    title: 'Question 1',
    text: 'Chaining swal2 modals is easy'
  },
  'Question 2',
  'Question 3'
]).then((result) => {
  if (result.value) {
    swal({
      title: 'All done!',
      html:
        'Your answers: <pre>' +
          JSON.stringify(result) +
        '</pre>',
      confirmButtonText: 'Lovely!'
    })
  }
})

All I get is

Your answers:
{"value":["question 1","question 2","question 3"]}

Thanks for the help.

Sweet Alerts 2

Upvotes: 1

Views: 3558

Answers (1)

user10757375
user10757375

Reputation:

You can use preConfirm

var strAns1;
var strAns2;

swal.mixin({
  input: 'text',
  confirmButtonText: 'Next &rarr;',
  showCancelButton: true,
  progressSteps: ['1', '2', '3']
}).queue([
  {
    title: 'Question 1',
    text: 'Chaining swal2 modals is easy',
    preConfirm: function(value)
            {
                strAns1= value;
            }
  },

  {
    title: 'Question 2',
    text: 'Chaining swal2 modals is easy',
    preConfirm: function(value)
            {
                strAns2= value;
            }
  }
]).then((result) => {
  if (result.value) {
    swal({
      title: 'All done!',
      html:
        'Your answers: <pre>' +
          JSON.stringify(result) +
        '<pre>Answer1- ' + strAns1+
        '<pre>Answer2- ' + strAns2+
        '</pre>',
      confirmButtonText: 'Lovely!'
    })
  }
})

Upvotes: 1

Related Questions