Thursday, November 26, 2009

Re: [jQuery] [validate] Specifying custom highlight/unhighlight methods problem

The validation plugin hides labels based on the error class. By adding that class to your regular label, it'll get hidden, too. Try using a different class for the regular label (with the same styles).

Jörn

On Wed, Nov 25, 2009 at 4:35 PM, Imre Farkas <farkasimre79@gmail.com> wrote:
I'm trying to specify a couple of custom methods for highlighting/
unhighlighting valid/invalid fields on my form, but I'm getting some
strange behaviour, which I'm not sure is due to me misunderstanding
how these methods are supposed to be implemented, or if it's just
buggy.

$().ready(function() {
       // validate signup form on keyup and submit
       $("#contactForm").validate({
               showErrors: function(errorMap, errorList) {
                       $("#result").html('<span class="errors"></span><span
class="msg">Please check/fill the marked fields</span> !');
                       this.defaultShowErrors();
               },
               highlight: function(element, errorClass) {
                        $(element.form).find("label[for=" + element.id + "]").addClass
(errorClass);
                 },
           unhighlight: function(element, errorClass) {
                        $(element.form).find("label[for=" + element.id + "]").removeClass
(errorClass);
                 },
               rules: {
                       name: "required",
                       email: {
                               required: true,
                               email: true
                       }
               }
       });
});
My problem is when some of inputs in invalid, then the label will take
the "error" class, will be turn on red, when I correct the content of
input my label disapear,  I have also the "valid" class, in my css
file, what colud be the problem

I hope You understand what I mean;

No comments: