Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 1.16 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jquery validator errorPlacement offset problem
  2. $(document).ready(function() {
  3.  
  4. var tabs = $("#tabs").tabs();
  5.  
  6. var validator = $("#myForm").validate({
  7.  
  8.         errorElement: "div",
  9.         wrapper: "div",  // a wrapper around the error message
  10.         errorPlacement: function(error, element) {
  11.  
  12.             if (element.parent().hasClass('group')){
  13.                 element = element.parent();
  14.             }
  15.  
  16.  
  17.             offset = element.position();
  18.             error.insertBefore(element)
  19.             error.addClass('message');  // add a class to the wrapper
  20.             error.css('position', 'absolute');
  21.             error.css('left', offset.left + element.outerWidth());
  22.             error.css('top', offset.top);
  23.  
  24.  
  25.         }
  26.     });
  27. }
  28.        
  29. $(document).ready(function() {
  30.  
  31.     var validator = $("#myForm").validate({
  32.             ... // your settings
  33.             ignore : ['#tabs .inactive input'] // tells the validator to only validate elements on your current tab
  34.         });
  35.     }
  36.  
  37.  
  38.     $(".forward").click(function() {
  39.         if (validator.form()) {  // triggers validation of the currently visible form inputs
  40.                 // step forward to the next tab
  41.         }
  42.     });
  43. });