5

I'm using this jQuery plugin: http://docs.jquery.com/Plugins/Validation/validate and it seems to always put the messages after the input element. is there a way to get them to append to before the element instead of after?

3 Answers 3

12

Check errorPlacement: options for plugin:

$("#myform").validate({
  errorPlacement: function(error, element) {         
       error.insertBefore(element);
   }
 })
Sign up to request clarification or add additional context in comments.

Comments

1

Use errorPlacement to control will allow you to put error message on specific place.

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

Here are a few samples of errorPlacement with error options as well

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

For custom error message and control creation

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

Comments

1

Check errorPlacement: options for plugin

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.