validate errorPlacement offset problem - how to call twice or refresh?

validate errorPlacement offset problem - how to call twice or refresh?

Hey all,

I'm trying to use errorPlacement with the Validator plugin for jquery, but I'm having issues with the offset. If the element is hidden at the time of validation (in a different tab), the offset returns the value 0,0 (top left corner of screen).


  1.     $(document).ready(function() {
  2.    
  3.     var tabs = $("#tabs").tabs();
  4.    
  5.     var validator = $("#myForm").validate({
  6.        
  7.             errorElement: "div",
  8.             wrapper: "div",  // a wrapper around the error message
  9.             errorPlacement: function(error, element) {
  10.                
  11.                 if (element.parent().hasClass('group')){
  12.                     element = element.parent();
  13.                 }
  14.                
  15.    
  16.                 offset = element.position();
  17.                 error.insertBefore(element)
  18.                 error.addClass('message');  // add a class to the wrapper
  19.                 error.css('position', 'absolute');
  20.                 error.css('left', offset.left + element.outerWidth());
  21.                 error.css('top', offset.top);
  22.                
  23.                
  24.             }
  25.         });
  26.     }

Any suggestions on how to fix this? I would recalculate the offsets when the tab changes or something, but it's being done in validate which I understood is only called once. Can I just refresh the validation or something? Or loop through the error elements somehow and reposition them?

Thanks for the help!