1

基本上,我需要在单击“下一步”按钮时验证数据,但是如果用户想要返回,我不想验证他们是否已经为当前步骤引入了必填字段

    $('#wizard').smartWizard({ onLeaveStep: leaveAStepCallback,
            onFinish: onFinishCallback
        });

        function leaveAStepCallback(obj) {
            var step_num = obj.attr('rel'); // get the current step number
            return validateSteps(step_num); // return false to stay on step and true to continue navigation 
        }

        function onFinishCallback() {
            if (validateAllSteps()) {
                $('form').submit();
            }
        }

        // Your Step validation logic
        function validateSteps(stepnumber) {
            var isStepValid = true;

            if (stepnumber == 1) {
                var e = document.getElementById("ContentPlaceHolder1_DropDownCustomers");
                var strCustomer = e.options[e.selectedIndex].value;
                if (strCustomer == "-1") {
                    //alert("Please select a Customer.");
                    $('#wizard').smartWizard('showMessage', 'Please select a Customer.');
                    isStepValid = false;
                    return isStepValid;
                }
                else {
                    var d = document.getElementById("ContentPlaceHolder1_DropDownTemplates");
                    var strTemplate = d.options[d.selectedIndex].value;
                    if (strTemplate == "-1") {
                        alert("Please select a Template.");
                        isStepValid = false;
                        return isStepValid;
                    }
                    else {
                        return isStepValid;
                    }
                    return isStepValid;
                }
            }

            if (stepnumber == 2) {

                if (document.getElementById("ContentPlaceHolder1_LabelMainDestData") != null) {
                    isStepValid = true;
                }
                else {
                    alert("Please introduce the Main Destination.");
                    isStepValid = false;
                }


                return isStepValid;

            }

            if (stepnumber == 3) {
                isStepValid = true;
                return isStepValid;
            }

        }
4

6 回答 6

3

在 showStep 函数中只需编辑

if(stepIdx != curStepIdx)

if(stepIdx > curStepIdx)

它会解决你的问题

于 2012-12-03T00:46:14.407 回答
1

创建一个新变量:

var OO_Back = false;

然后在单击返回按钮时添加“OO_Back = true”:

$($this.buttons.previous).click(function() {
    OO_Back = true;
    $this.goBackward();
    return false;
});

最后修改此条件以检查单击后退按钮,之后必须设置 OO_Back = false :

 var curStep = $this.steps.eq($this.curStepIdx);
    if(stepIdx != $this.curStepIdx){
        if($.isFunction($this.options.onLeaveStep) && OO_Back == false) {
            var context = { fromStep: $this.curStepIdx+1, toStep: stepIdx+1 };
            if (! $this.options.onLeaveStep.call($this,$(curStep), context)){
                return false;
            }
        }
    }
 OO_Back = false;
于 2012-02-12T20:09:38.940 回答
0

只需在 step_number 属性上创建另一个 jsp 页面,您可以从请求中获取该属性,并在该 jsp 中根据您的 step_number 包含您的 jsp,并在您的 contentURL 中分配新创建的 jsp

例子

//inside your wizard page.
contentURL:'wizardcontent.jsp',

//'wizardcontent.jsp' is as follow

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
    int step_number = Integer.parseInt(request.getParameter("step_number")!=null?request.getParameter("step_number"):"1");
    String url = "";
    switch (step_number){
        case 1:%>
            <jsp:include page="ddd.jsp"></jsp:include>
        <%break;
        case 2:%>
            <jsp:include page="xyz.jsp"></jsp:include>
        <%break;
        case 3:%>
            <jsp:include page="abcd.jsp"></jsp:include>
                   <%break;
    }

%>
于 2011-09-09T09:14:26.133 回答
0

也许这可以帮助:

       $('.buttonPrevious').click(function () {
            // set true validation if you need
            return false;
        });

如果需要,您必须在后退按钮上设置有效的 true。

试试这个取消 leaveAStepCallback 功能。

       $('#yourwizard').unbind('leaveAStepCallback'); 

如果它不起作用,请查看stopImmediatePropagation

于 2012-02-10T10:48:37.017 回答
0

我使用了以下内容,并且在上面接受的答案的指导下完美运行。

onLeaveStep: function(obj, context){
       if(context.toStep > context.fromStep){ ...}
  }
于 2013-08-30T01:15:03.180 回答
0

当我使用它时,这对我有用:

 function leaveStep(oStep, context) {
   //don't validate if the user is going backwards    
    if (context.toStep < context.fromStep)
    {
        $('#wizard').smartWizard('hideMessage');
        return true;
    }
   // continue to validate steps...
于 2015-06-29T20:31:49.993 回答