views:

32

answers:

2

I want to have site wide default settings for all jQuery validation uses on my site, I want every form to use the below settings, but then on a per form basis change the rules and messages. Is this possible?

 $('#myForm').validate({

  errorClass: 'field-validation-error',
  errorElement: 'span',
  errorPlacement: function(error, element) {
        element.next('span').remove();
        error.insertAfter( element )
         .removeClass('field-validation-error')
         .addClass('ui-state-error');

    },
    success: function(label) {
            label.remove();
  }          
});
+1  A: 

I found it

jQuery.validator.setDefaults({ 
   errorClass: 'field-validation-error',
  errorElement: 'span',
  errorPlacement: function(error, element) {
        element.next('span').remove();
        error.insertAfter( element )
         .removeClass('field-validation-error')
         .addClass('ui-state-error');

    },
    success: function(label) {
                label.remove();
    }
});
Daveo
+2  A: 

Put those codes within

jQuery.validator.setDefaults({ //your site wide codes });

And save it into a site wide js file, e.g. global.js

itpretty