Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to change error placement according to the details entered in field. i.e if field is empty then display error after submit button else if the field is not empty but the min length or max length is not matched the display error after element.

I tried this but its not working.

errorPlacement: function(error, element) {
if(error.text() === "Please fill the field.")
{ 
  if(element.val() === ""){
    $(".login-empty-error").html(error);
  } else {
    error.insertAfter(element);
  }
} else {
  error.insertAfter(element);
}
}

How to find whether the type is required?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
276 views
Welcome To Ask or Share your Answers For Others

1 Answer

How to change error placement according to the details entered in field.

The errorPlacement option cannot do anything like this. Once the error element container is placed within the layout using errorPlacement, the plugin simply toggles this element as needed. Its location is not changed as the element is already there but hidden.

In other words, you cannot dynamically move the error element around the form using any of the provided options or methods.

However, if you want a message to appear near the button when there are errors within the form, look at the showErrors option.

showErrors: function (errorMap, errorList) {
    if (this.numberOfInvalids() > 0) {
        $("#summary").html("Your form contains " + this.numberOfInvalids() + " errors, see details above.");
    } else {
        $("#summary").empty();
    }
    this.defaultShowErrors(); // <- default messages that appear within form
}

Basic usage demo: http://jsfiddle.net/v2h2a2mb/

You could tweak this function so that a message only appears under certain conditions. The built-in arguments are described below...

errorMap, Type: Object, Key/value pairs, where the key refers to the name of an input field, values the message to be displayed for that input.

errorList, Type: Array, An array for all currently validated elements. Contains objects with the following two properties:

  • message, Type: String, The message to be displayed for an input.

  • element, Type: Element, The DOMElement for this entry.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...