eddy
eddy

Reputation: 4413

jQuery validate -How do I remove a specific error message without removing any other error messages?

See: jsFiddle

I'm trying to remove only a specific error message ("Select a department"), when a different option to "External" is selected from the select list "Role", since only when a user role is "External" I need to specify which department that user belongs to.

I've only been able to remove the error style using removeClass("error"), but even after I've removed that class, the error message is still display and it only disappears if I attempt to submit the form and that's not what I want, what I want to do is to make that error message ("Select a department") disappear as soon as another user role is selected(a role different to "external" of course)

In order for you to understand me more easily I have put up a jsFiddle.

I really hope you can help me out

Upvotes: 3

Views: 2219

Answers (1)

Majid Fouladpour
Majid Fouladpour

Reputation: 30272

Just add department.next().hide(); after the line that disables the select. See this.

...
role.change(function() {
    if (role.val()=="EU"){
        ...
    } else{
        department.removeClass("error");
        department.attr("disabled", true);    
        department.next().hide();
        $("#password").focus();
    }
});
...

Upvotes: 3

Related Questions