开发者

validate a subset of the input elements

I have started using jQuery Validation plugin 1.7.

I have a wizard like interface that collect input for several view model classes. I am trying to validate every object showed in a step every time the user click on the NEXT/PREVIOUS button.

My jquery code is like this one

$w.bind("jwizardchangestep", function (event, ui) {
    if (ui.type !== "manual") {
        var $currentStep = $w.find(".jw-step:eq(" + ui.currentStepIndex + ")");
        var $inputs = $currentStep.find("input:text");

        if ($inputs.length > 0 && !$inputs.valid()) {
            $currentStep.find("label.error").effect("highlight");
            return false;
        }
    }
});

where $inputs contains a reference to all the input boxes in the page.

Anyway the function $inputs.valid() always return true even if the input elements have not be filled at all. I am suspecting that something is wrong with the validation rules that I specify in another jQuery call like this one

$("#registerForm").validate({
    rules: {
        Firm_Name: "required",
        Firm_StreetAddress: "required",
        Firm_ZipCode: "required",
        Firm_City: "required"
    }
});

This is a sample markup code of an input box

<input id="Firm_Name" name="Firm.Name" style="width: 460px;" type="text" value="" class="ui开发者_JS百科-widget-content">


try using names

$("#registerForm").validate({
    rules: {
        Firm.Name: "required",
        Firm.StreetAddress: "required",
        Firm.ZipCode: "required",
        Firm.City: "required"
    }
});


I have got it working using rules in metadata.

It seems that the call

$("#registerForm").validate({
    rules: {
        Firm_Name: "required",
        Firm_StreetAddress: "required",
        Firm_ZipCode: "required",
        Firm_City: "required"
    }
});

will setup the rules to be checked at submit time which is not properly what I wanted to do because I wanted to validate on every wizard next button click.

Using rules in metadata as

<input id="Firm_Name" name="Firm.Name" 
    style="width: 460px;" type="text" value="" 
    class="required ui-widget-content">

works very nice. Thanks everybody for helping

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜