jQuery Validation - How to display the default callout on errors?

前端 未结 3 1725
长情又很酷
长情又很酷 2021-01-16 16:30

If I create an input control like this:


And type letters in it, an error will be displayed in a popup-like co

相关标签:
3条回答
  • 2021-01-16 17:10

    That 'callout' as you refer to it is actually chromes way of interpreting the spec, the error message will look different or not pop up at all in some browsers

    stares at IE

    0 讨论(0)
  • 2021-01-16 17:13

    Your picture shows the default HTML5 validation which is rendered (or not rendered) depending solely on the specific browser version.

    http://i.stack.imgur.com/ZGi5z.jpg

    The browser must support HTML5 validation in order to see these pop-ups and Chrome's pop-ups will look different than Firefox's, etc. HTML5 validation is configured using HTML5 validation attributes that you'd add inline to each input element like this...

    <input type="number" required="required" max="5" ....
    

    However, when you employ the jQuery Validate plugin, it dynamically adds the novalidate attribute to the <form> tag...

    <form novalidate="novalidate" id="myform" ....
    

    The novalidate attribute is used to disable the HTML5 validation so that jQuery Validate can take over all form validation without interference from HTML5. Yes, the default jQuery Validate labels are bland, but that's the "blank canvas" which allows design flexibility and cross-browser consistency and reliability. See below.


    If you want error messages that look more like the pop-ups you'd get with HTML5, then you can create your own with CSS/jQuery.

    Quote:

    "Is there a simple way to make my custom error messages show up in the same way?"

    That depends on if you think adding another jQuery plugin is simple. You could integrate a jQuery plugin like qTip2 or ToolTipster into jQuery Validate. These plugins have many options, themes, and CSS that you can customize to no end. It can be tricky though as each plugin gets integrated differently depending on how it works, its manipulation methods, callbacks, etc.

    Here's a working demo showing how ToolTipster v3 (default - no theme) was easily integrated into jQuery Validate:

    http://jsfiddle.net/2DUX2/3/

    enter image description here

    Source: How to display messages from jQuery Validate plugin inside of Tooltipster tooltips?

    0 讨论(0)
  • 2021-01-16 17:16

    This is what you are talking is HTML5 feature use required attribute with your form element

    <input required>
    

    and it will show you default error message but if you want to show custom error message than use title attribute

    <input required title="Custom error message">
    

    Check this URL for more information http://demosthenes.info/blog/848/Create-Custom-HTML5-Form-Error-Messages-with-the-Title-Attribute

    Hope it will answer your question

    0 讨论(0)
提交回复
热议问题