【问题标题】:jQuery Smart Wizard Step VerificationjQuery 智能向导步骤验证
【发布时间】:2017-11-24 13:56:55
【问题描述】:

我在每一步都使用 jQuery Smart Wizard 来保存表单,我有一些输入字段。我想在进行下一步之前验证每个字段。 请帮助我如何实现它。

这是我的 jQuery:

$('#smartwizard').smartWizard({ 
    selected: 0, 
    theme: 'default',
    transitionEffect:'fade',
    showStepURLhash: true,
    toolbarSettings: {toolbarPosition: 'bottom',
    toolbarExtraButtons: [btnFinish, btnCancel]
    }
});

【问题讨论】:

    标签: jquery html smart-wizard


    【解决方案1】:

    您可以在点击下一步时检查表单是否有效。

    $(document).ready(function() {
        $('#smartwizard').smartWizard({ 
            onLeaveStep:leaveAStepCallback,
            onFinish:onFinishCallback
        });
    
        $("form").validate({
            rules: {
                'student[business_representative_attributes][first_name]': 'required'
            },
            messages: {
                'student[business_representative_attributes][first_name]': 'Please enter first name'
            }
        });
    });
    
    function leaveAStepCallback(obj, context){
        alert("Leaving step " + context.fromStep + " to go to step " + context.toStep);
        // return false to stay on step and true to continue navigation 
        if ($('form').valid()) {
            return true;
        } else {
            return false; 
        }
    }
    

    智能向导 4

    $("#smartwizard").on("leaveStep", function(e, anchorObject, stepNumber, stepDirection) {
         return confirm("Do you want to leave the step "+stepNumber+"?");
    });
    

    【讨论】:

    • 感谢帮助 pratik 但它不起作用什么是“用户名”是字段的名称吗?我有一个名为“student[business_representative_attributes][first_name]”的字段,我将如何验证它?
    • 用户名只是一个例子。您可以在那里使用字段。我使用了用户名,因为我没有您的表单字段。
    • $("form").validate({ rules: { 'student[business_representative_attributes][first_name]': "required" } });这是行不通的。即使我试图调试它也不会进入'leaveAStepCallback'函数。
    • 我的答案已经改了。
    • 我们需要定义'leaveAStepCallback'函数吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多