Validate between fieldsets

余生颓废 提交于 2019-12-31 03:26:21

问题


I'm using the formtowizard jquery plugin with bassistance validation. I have attached my next button to a click event which validates my form however I only want it to validate the current fieldset not the whole form...

My form is set up like this

<form id="SignupForm" method="POST" action="..................">

    <fieldset>
    <legend>Application</legend>
        <div>

        </div>
    </fieldset>

    <fieldset>
    <legend>Step Two</legend>
        <div>

        </div>
    </fieldset>

This is what I'm using at the moment

  $("a.next").click(function() {
  $("#SignupForm").validate();
  });

This is where my button gets called

function createNextButton(i) {
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next</a>");

            $("#" + stepName + "Next").bind("click", function(e) {
                /* VALIDATION */
                if (options.validationEnabled) {
                    var stepIsValid = true;
                    $("#"+stepName+" :input").each(function(index) {
                        checkMe = element.validate().element($(this));
                        //stepIsValid = !element.validate().element($(this)) && stepIsValid;
                        stepIsValid = checkMe && stepIsValid;
                    });
                    //alert("stepIsValid === "+stepIsValid);
                    if (!stepIsValid) {
                        return false;
                    };
                }; 

                $("#" + stepName).hide();
                $("#step" + (i + 1)).show();
                if (i + 2 == count)
                    $(submmitButtonName).show();
                selectStep(i + 1,'next');
            });
        }

Any ideas anyone?


回答1:


Ok I've managed to solve my problem if anyone else would like to know...

function createNextButton(i) {
    var stepName = "step" + i;
    $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next</a>");

    $("#" + stepName + "Next").bind("click", function(e) {

        if (options.validationEnabled) {
            var stepIsValid = true;
            $("#"+stepName+" :input").each(function(index) {
                checkMe = element.validate().element($(this));
                //stepIsValid = !element.validate().element($(this)) && stepIsValid;
                stepIsValid = checkMe && stepIsValid;
            });
            alert("stepIsValid === "+stepIsValid);
            if (!stepIsValid) {
                return false;
            };
        }; 

        $("#" + stepName).hide();
        $("#step" + (i + 1)).show();
        if (i + 2 == count)
            $(submmitButtonName).show();
        selectStep(i + 1,'next');
    });
}


来源:https://stackoverflow.com/questions/4396801/validate-between-fieldsets

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