Solution 1 :

You don’t tell us, but I’ll assume you’re using the validation library linked here.

You should be able to add functionality within an invalidHandler, e.g. something think this:

$(".woocommerce-ResetPassword").validate({
    onfocusout: false,
    onkeyup: false,
    rules: {
        password_2: {
            equalTo: "#password_1"
        }
    },
    messages: {
        password_2: "<div class='woocommerce-password-strength bad'>Passwords do not match</div>"
    },
    submitHandler: function(form) {
       $(".woocommerce-form-row--last").removeClass("notif-triggered");
       return true;
    },
    invalidHandler: function(event, validator) {
       $(".woocommerce-form-row--last").addClass("notif-triggered");
    }
});

Problem :

I am using jQuery validation library to validate both password inputs to have the same value. My code is written below.

$(".woocommerce-ResetPassword").validate({
    onfocusout: false,
    onkeyup: false,
    rules: {
        password_2: {
            equalTo: "#password_1"
        }
    },
    messages: {
        password_2: "<div class='woocommerce-password-strength bad'>Passwords do not match</div>"
    },
    submitHandler: function(form) {
    return true;
    }
});

I want to execute a jQuery code to add a class to an element when the notification of password_2 appears.

I want to modify this part of the code by adding a jQuery script inside the messages: {} but the code below does not work. You can see that I added $(".woocommerce-form-row--last").addClass("notif-triggered");

messages: {
    password_2: "<div class='woocommerce-password-strength bad'>Passwords do not match</div>"
    $(".woocommerce-form-row--last").addClass("notif-triggered");
},

Any help is greatly appreciated. Thanks.

Comments

Comment posted by Always Helping

is this resolved now ?

Comment posted by redshot

@AlwaysHelping Yes

By