首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >基于if语句链接额外的甜蜜警报

基于if语句链接额外的甜蜜警报
EN

Stack Overflow用户
提问于 2018-06-06 06:20:37
回答 1查看 2K关注 0票数 2

我正在尝试使用SweetAlert2创建一个逐步的表单,并且我需要能够基于if语句在我的链接中添加额外的步骤。

例如,在我的第三个模式中,我可能有一个单选问题,说“你会带一个加1吗?”,如果用户选择“true”,我需要弹出一个额外的阶段,询问“name of plus 1”,如果用户选择“false”,则只需继续。

代码语言:javascript
复制
swal.mixin({
        confirmButtonText: 'Next →',
        showCancelButton: true,
        progressSteps: ['1', '2', '3', '4']
      }).queue([
        {
            title: 'Which event?',
            text: 'Please start by selecting the event you would like to book in!',
            input: 'select',
            inputClass: 'swal-select-event',
            inputPlaceholder: 'Please Select',
            inputOptions: {
                '1' : 'Dance Event',
                '2' : 'Football Event'
            },
            inputValidator: (value) => {
                return new Promise((resolve) => {
                  if (value === '') {
                    resolve('You need to select an event!')
                  } else {
                    resolve()
                  }
                })
            }
        },
        {
            title: 'What Day?',
            text: 'Which day are they due to come in?',
            html:'<input id="swal-booking-date-select" type="date"/>',
            preConfirm: () => {
                return document.getElementById('swal-booking-date-select').value
            },
            inputValidator: (value) => {
                return new Promise((resolve) => {
                  if (value === '') {
                    resolve('You need to select a date!')
                  } else {
                    resolve()
                  }
                })
            }
        },
        {
            title: 'Plus one?',
            text: 'Will you be bringing a plus one with you?',
            input: 'radio',
            inputOptions: {
                    'yes' : 'Yes',
                    'no' : 'No'
                },
            inputValidator: (value) => {
                return new Promise((resolve) => {
                    if (value === null) {
                        resolve('I need to know if you will be bringing a plus 1!')
                    } else if(value === 'yes') {


                        //EXTRA STAGE GOES HERE TO GET PLUS ONE NAME


                    } else {
                        resolve()
                    }
                })
            }
        },
        {
            title: 'What else?',
            input: 'text',
            text: 'Any other information that needs noting for this booking?'
        }
      ]).then((result) => {
        if (result.value) {
            //Do something with all of the data here
        }
      })

有没有人知道这是否可能?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50709734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档