I've got a form where I'm using jQuery validation on its elements. The form contains two text fields and a set of checkboxes. The relevant part of my code looks like this:
$.validator.addMethod('require-one', function (value) {
return $('.require-one:checked').size() > 0;
}, 'Who should see your question?');
var checkboxes = $('.require-one');
var checkbox_names = $.map(checkboxes, function(e,i) { return $(e).attr('name')}).join(' ');
$('FORM#node-form').validate({
groups: { checks: checkbox_names },
errorPlacement: function(error, element)
{
if (element.attr('type') == 'checkbox') {
error.insertAfter('#user_role_buttons > div > label');
}
else {
error.insertAfter(element);
}
}
});
The new method and "checkboxes" stuff is required for the checkboxes to be handled as a group, and that's actually working correctly, including the placement of the error message inside that #user_role_buttons thing.
My problem/question is that I can't find any way to set the placement of error messages for the two text elements. The validation is working correctly for those items; I just can't specify their position. In particular, errors involving those items aren't showing up in the errorPlacement clause of the validate handler: If I put a console.log(element) statement inside the errorPlacement's function to see what's going on, the only thing that shows up is the error involving the checkboxes (assuming there is one). The messages for the text items are getting placed somewhere semi-reasonable, but not where I want them.
I must be missing something; can anybody see what it is?