views:

38

answers:

1

Due to space limitations I'm trying to place the error messages for a form inside tooltips.

$("form").validate({
        rules: {
            username: { required: true, email: true },
            password: "required"
        },
        onkeyup: true,
        success: "valid",
        errorPlacement: function(error, element) {
            var msg = errorList[i].message;
            element.attr('title', msg);
        }
    });

The element.attr part works fine- I'm just having trouble extracting the message to put in it. Where does it reside?

+1  A: 

There are several issues with your code

  • errorList is undefined
  • i is undefined

but this should just work fine I guess (although I don't know how the plugin reacts as it probably expects the error element to be inserted into the DOM after this callbacK)

errorPlacement: function(error, element) {
    element.attr('title', error.text());
    //or if that doesn't work try also 
    //element.attr('title', error[0].text);
}
jitter