Jquery validate, put messages in front of input field

I use this jQuery plugin: http://docs.jquery.com/Plugins/Validation/validate and seems to always put messages after the input element. Is there a way to get them to add before the element, and not after?

+5
source share
3 answers

Check the errorPlacement: parameters for the plugin:

 $("#myform").validate({ errorPlacement: function(error, element) { error.insertBefore(element); } }) 
+10
source

Using errorPlacement for control will allow you to place an error message in a specific place.

 $("#myform").validate({ errorPlacement: function(error, element) { error.appendTo(element.parent("td").next("td") ); } }); 

Here are some examples of errorPlacement with error options

  • error.appendTo (element.parent ("DIV") next ("DIV").);
  • error.appendTo ($ ('# identifier'));
  • error.insertAfter (element);
  • error.insertBefore (element);

For custom error messages and creating controls

 errorPlacement: function(error, element) { var elementForm = "", containerError = ""; offset = element.offset(); elementForm = element.attr("name"); containerError = "#" + elementForm + "error"; error.prependTo(containerError); error.addClass('message'); } 
0
source

Check errorPlacement: parameters for plugin

 $("#myform").validate({ errorPlacement: function(error, element) { element.before(error); } }); 
-1
source

All Articles