Hi there,

I have two issues here:

a) When adding a method to the validator the message does not return
on an error
b) Even though the added method returns false the submit handler still
submits the form.

Any suggestions?

Here the code:

$.validator.addMethod("userExists", function(value, element) {
                        var r = true;
                        var jqe = $(element);

                        
jqe.parent("td").next().children("div").empty().append('&nbsp;<img
src="images/validate_loader.gif" width="16" height="16" />');
                        $.get("ajaxindex.php?module=validate&action=username",
                          { username: value },
                          function(data){
                                if(data=="false") {
                                        
jqe.parent("td").next().children("div").empty().append('&nbsp;<b
class="error-style">*</b>');
                                        jqe.focus();
                                        r = false;
                                } else {
                                        
jqe.parent("td").next().children("div").empty().append(' &nbsp;
');
                                }
                          });
                          return r;
                }, "The username already exists.");
                $.validator.addMethod("emailExists", function(value, element) {
                        var r = true;
                        var jqe = $(element);
                        
jqe.parent("td").next().children("div").empty().append('&nbsp;<img
src="images/validate_loader.gif" width="16" height="16" />');
                        $.get("ajaxindex.php?module=validate&action=email",
                          { email: value },
                          function(data){
                                if(data=="false") {
                                        
jqe.parent("td").next().children("div").empty().append('&nbsp;<b
class="error-style">*</b>');
                                        jqe.focus();
                                        r = false;
                                } else {
                                        
jqe.parent("td").next().children("div").empty().append(' &nbsp;
');
                                }
                          });
                          return r;
                }, "The email address already exists.");
                $("#register_form").validate({
                        errorLabelContainer: $("#error_li"),
                        wrapper: "li",
                        rules: {
                                reg_username: {
                                        required: true,
                                        minLength: 4,
                                        maxLength: 120,
                                        userExists: true
                                },
                                reg_password: {
                                        required: true,
                                        minLength: 4
                                },
                                reg_confirm_password: {
                                        equalTo: "#reg_password"
                                },
                                reg_email: {
                                        email: true,
                                        required: true,
                                        emailExists: true
                                }
                         },
                         messages: {
                                 reg_username: {
                                        required: "A valid username is 
required.",
                                        minLength: "Please enter a username at 
least 4 characters long.",
                                        maxLength: "Please enter a username no 
longer then 120
characters long."
                                 },
                                 reg_password: {
                                        required: "A password is required.",
                                        minLength: "Please enter a password at 
least 4 characters long."
                                 },
                                 reg_email: {
                                        required: "A valid email address is 
required."
                                 }
                         },
                        submitHandler: function(form) {
                                $(form).ajaxSubmit(options);
                    }
                });

Thanks for the help.
Thomas

Reply via email to