views:

35

answers:

1

hi i have added a rule to my form but i can't understand why it does not work!!

http://www.pipelabitta.it/form/

This is an example page: the rules is that the check box must be checked and there must be a valid date. From firefox console i can see it returns true or false as i need but the validation does not get triggered.

Why is that?

Thanks Vitto

A: 
    aaaaAgg: {
                required: function(){
                    var g = $("input[name=ggAgg]").val();
                    var m = $("input[name=mmAgg]").val();
                    var a = $("input[name=aaaaAgg]").val();
                    var d = g + '/' + m + '/' + a;
                    var reg = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/(19\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/(19\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/(19\d{2}))|(29\/02\/(19(0[48]|[2468][048]|[13579][26]))))$/;
                    var c = reg.test(d) && $("#cartaAggiuntiva").is(":checked");
                    console.log(c);
                    return ( c );
                },
            }

means that aaaaAgg is required depending on the returned value of that function required: function(){..} but it will be only run once ( and only once) the page loads, and that's that... if the function returns true, so it's required, otherwise not... I would suggest you read this addMethod(). a demo of that kind here.

Reigel
hi reigel,i modified the page and addes a metohd..but now the validation is always triggered and it returns false even if i do not check the checkbox!!why is that? Should the method be called only if both the rules return true?
vitto