JQuery многошаговая проверка формы - PullRequest
7 голосов
/ 23 июня 2009

Мне нужно проверить многошаговую форму. Есть ли достойные плагины для этого?

Например:

$(function() {
    $('#MoveStep1').click(function() {
        $("#step1").validate();
    });
});

#step1 - это набор полей.

Ответы [ 2 ]

1 голос
/ 26 июня 2009

Я предлагаю это, только если вы в порядке с быстрым взломом в 4 строки

//untested but you'll get the gist, you may need a slight variation on this
$("#step1").wrap('<form id="tmp-form"></form>');
$("#tmp-form").validate();
$("#step1").insertBefore("#tmp-form");
$("#tmp-form").remove();

Основная идея - обернуть его во временную форму. Подтвердить. Удалить. Повторите.

Benefits:  
use a validation plugin you already know and is well-tested. 
you don't need to change any existing validation rules

Cons:
possible undesired layout effects depending on you style markup
maybe others? once again, not tested just a quick thought
0 голосов
/ 10 июня 2011

Как насчет этого:

//setup validation, don't validate if the control is: ignored, inside an ignored container, or hidden
$("form").validate({ ignore: ".ignore, .ignore *, :hidden" });

$("#MoveStep1").click(function() {
    //assuming each step is in a container with the class Step
    $(".Steps:not(#step1)").addClass(.ignore);
    $("form").valid();
    $(".Steps").removeClass(.ignore);
});
...