简体   繁体   English

如何使用后退按钮添加自定义队列

[英]How to add custom queues with back button

I am reviewing the documentation example of SweetAlert2, which generates a window with steps and includes the button to go back.我正在查看 SweetAlert2 的文档示例,它生成一个带有步骤的窗口并包含返回按钮。

I can't find a way to configure the different queues as I want.我找不到根据需要配置不同队列的方法。 According to the documentation, one can configure it with .queue (), but it is not working for me.根据文档,可以使用 .queue() 对其进行配置,但它对我不起作用。

Does anyone know how to do it?有谁知道怎么做?

 const steps = ['1', '2', '3'] const swalQueueStep = Swal.mixin({ confirmButtonText: 'Forward', cancelButtonText: 'Back', progressSteps: steps, input: 'text', inputAttributes: { required: true }, reverseButtons: true, validationMessage: 'This field is required' }) async function backAndForth () { const values = [] let currentStep for (currentStep = 0; currentStep < steps.length;) { const result = await swalQueueStep.fire({ title: 'Question ' + steps[currentStep], inputValue: values[currentStep], showCancelButton: currentStep > 0, currentProgressStep: currentStep }) if (result.value) { values[currentStep] = result.value currentStep++ } else if (result.dismiss === 'cancel') { currentStep-- } else { break } } if (currentStep === steps.length) { Swal.fire(JSON.stringify(values)) } } backAndForth()
 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>

const steps = ['1', '2', '3']
const swalQueueStep = Swal.mixin({
    confirmButtonText: 'Forward',
    cancelButtonText: 'Back',
    progressSteps: steps,
    input: 'text',
    inputAttributes: {
        required: true
    },
    reverseButtons: true,
    validationMessage: 'This field is required'
})
async function backAndForth() {
    const values = []
    let currentStep
    for (currentStep = 0; currentStep < steps.length;) {
        if (steps[currentStep] == 1) {
            var result = await swalQueueStep.fire({
                title: 'Question .' + steps[currentStep],
                inputValue: values[currentStep],
                showCancelButton: currentStep > 0,
                currentProgressStep: currentStep
            })
        } else if (steps[currentStep] == 2) {
            var result = await swalQueueStep.fire({
                title: 'Question ..' + steps[currentStep],
                inputValue: values[currentStep],
                showCancelButton: currentStep > 0,
                currentProgressStep: currentStep
            })
        } else if (steps[currentStep] == 3) {
            var result = await swalQueueStep.fire({
                title: 'Question ...' + steps[currentStep],
                inputValue: values[currentStep],
                showCancelButton: currentStep > 0,
                currentProgressStep: currentStep
            })
        } else {
            break
        }
        if (result.value) {
            values[currentStep] = result.value
            currentStep++
        } else if (result.dismiss === 'cancel') {
            currentStep--
        } else {
            break
        }

        if (currentStep === steps.length) {
            Swal.fire(JSON.stringify(values))
        }
    }
}
backAndForth();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM