0

I have this validation code:

$("#validate").validate({
        rules: {

            // My other rules
            // My other rules
            // My other rules

            minecraft: {
                required: true,
                remote: "./validate-minecraft.php"
            }
        },
        messages: {
            minecraft: {
                remote: "error."
            }
        },
        errorClass: "help-inline",
        errorElement: "span",
        highlight: function (element, errorClass, validClass) {
            $(element).parents('.control-group').addClass('error');
        },
        unhighlight: function (element, errorClass, validClass) {
            $(element).parents('.control-group').removeClass('error');
            $(element).parents('.control-group').addClass('success');
        },
        submitHandler: function (form) {
            jQuery("#btn-submit").addClass("disabled");
            ("validate").submit();
        }
    });

Everything works correctly excepts for the minecraft field, with remote.

My PHP script validate-minecraft.php returns true or false correctly, the error message is displayed correctly if it returns false, however the field color is changed to green instead of red when there is an error.

What am I doing wrong?

Thanks!

1 Answer 1

1

Maybe you need to remove the "success" class on highlight.

highlight: function (element, errorClass, validClass) {
    $(element).parents('.control-group').removeClass('success');    
    $(element).parents('.control-group').addClass('error');
},

When I tested on your site, I noticed that the control-group div looked like this:

<div class="control-group success error">

Now the weird thing is that it does this even when error on my first try. Not sure how the success class gets added. But maybe this is has to do with the remote validator? I tried this locally with a digits validator and it did not add the success class on the initial error.

Either way you should remove the success class on user input error anyway.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.