0

If I create an input control like this:

<input type="number">

And type letters in it, an error will be displayed in a popup-like control. I've seen it referred to as a callout but I'm not sure if that's the right name. It looks like this:

enter image description here

But if I define my own rules in either the jQuery Validation Plugin or in ASP.NET then there's no fancy popup anymore, just a label which is appended. It doesn't look nearly as good and it isn't very consistent with the above either.

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

Sparky
  • 98,165
  • 25
  • 199
  • 285
StefanLundmark
  • 313
  • 3
  • 11
  • 1
    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* – MarshallOfSound Nov 01 '14 at 04:36
  • Interesting, I just tested on Firefox and you're right! Would you mind posting this as an answer? – StefanLundmark Nov 01 '14 at 07:45

3 Answers3

3

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

https://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?

Community
  • 1
  • 1
Sparky
  • 98,165
  • 25
  • 199
  • 285
1

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

Milind
  • 1,855
  • 5
  • 30
  • 71
1

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

MarshallOfSound
  • 2,629
  • 1
  • 20
  • 26
  • I see some downvotes on this answer guys, please leave a comment explaining why you think it is bad. Bearing in mind it is just a simplified version of the answer marked correct – MarshallOfSound Jun 23 '15 at 02:37