Sweet Alerts - Queue form

人走茶凉 提交于 2021-01-28 08:48:54

问题


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


回答1:


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!'
    })
  }
})


来源:https://stackoverflow.com/questions/50847738/sweet-alerts-queue-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!