Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:04:29+00:00 2026-06-06T16:04:29+00:00

I want to display my jQuery validation messages in a tooltip. In order to

  • 0

I want to display my jQuery validation messages in a tooltip. In order to accomplish this, I started out by adding the following CSS rules to my stylesheet:

fieldset .field-validation-error {
    display: none;
}

fieldset .field-validation-error.tooltip-icon {
    background-image: url('/content/images/icons.png');
    background-position: -32px -192px;
    width: 16px;
    height: 16px;
    display: inline-block;
}

and a very small piece of JS code:

; (function ($) {
    $(function() {
        var fields = $("fieldset .field-validation-valid, fieldset .field-validation-error");
        fields.each(function() {
            var self = $(this);
            self.addClass("tooltip-icon");
            self.attr("rel", "tooltip");
            self.attr("title", self.text());
            self.text("");
            self.tooltip();
        });
    });
})(jQuery);

The issue is that I now need to capture any event when the validation message changes, I’ve been looking at the source for jquery.validate.unobtrusive.js, and the method I’d need to hook to is the function onError(error, inputElement) method.

My tooltip plugin works as long as I’ve an updated title attribute, the issue comes when the field is revalidated, and the validation message is regenerated, I would need to hook into that and prevent the message from being put out there and place it in the title attribute instead.

I want to figure out a way to do this without modifying the actual jquery.validate.unobtrusive.js file.

On a second note, how could I improve this in order to leave the functionality unaltered in case javascript is disabled?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:04:31+00:00Added an answer on June 6, 2026 at 4:04 pm

    Ok I went with this, just in case anyone runs into this again:

    ; (function ($) {
        $(function() {
            function convertValidationMessagesToTooltips(form) {
                var fields = $("fieldset .field-validation-valid, fieldset .field-validation-error", form);
                fields.each(function() {
                    var self = $(this);
                    self.addClass("tooltip-icon");
                    self.attr("rel", "tooltip");
                    self.attr("title", self.text());
                    var span = self.find("span");
                    if (span.length) {
                        span.text("");
                    } else {
                        self.text("");
                    }
                    self.tooltip();
                });
            }
    
            $("form").each(function() {
                var form = $(this);
                var settings = form.data("validator").settings;
                var old_error_placement = settings.errorPlacement;
                var new_error_placement = function() {
                    old_error_placement.apply(settings, arguments);
                    convertValidationMessagesToTooltips(form);
                };
                settings.errorPlacement = new_error_placement;
                convertValidationMessagesToTooltips(form); // initialize in case of model-drawn validation messages at page render time.
            });
        });
    })(jQuery);
    

    and styles:

    fieldset .field-validation-error { /* noscript */
        display: block;
        margin-bottom: 20px;
    }
    
    fieldset .field-validation-error.tooltip-icon { /* javascript enabled */
        display: inline-block;
        margin-bottom: 0px;
    
        background-image: url('/content/images/icons.png');
        background-position: -32px -192px;
        width: 16px;
        height: 16px;
        vertical-align: middle;
    }
    

    I’ll just include the tooltip script I have, since it’s kind of custom-made (though I based it off someone else’s).

    ; (function ($, window) {
        $.fn.tooltip = function (){
            var classes = {
                tooltip: "tooltip",
                top: "tooltip-top",
                left: "tooltip-left",
                right: "tooltip-right"
            };
    
            function init(self, tooltip) {
                if ($(window).width() < tooltip.outerWidth() * 1.5) {
                    tooltip.css("max-width", $(window).width() / 2);
                } else {
                    tooltip.css("max-width", 340);
                }
    
                var pos = {
                    x: self.offset().left + (self.outerWidth() / 2) - (tooltip.outerWidth() / 2),
                    y: self.offset().top - tooltip.outerHeight() - 20
                };
    
                if (pos.x < 0) {
                    pos.x = self.offset().left + self.outerWidth() / 2 - 20;
                    tooltip.addClass(classes.left);
                } else {
                    tooltip.removeClass(classes.left);
                }
    
                if (pos.x + tooltip.outerWidth() > $(window).width()) {
                    pos.x = self.offset().left - tooltip.outerWidth() + self.outerWidth() / 2 + 20;
                    tooltip.addClass(classes.right);
                } else {
                    tooltip.removeClass(classes.right);
                }
    
                if (pos.y < 0) {
                    pos.y = self.offset().top + self.outerHeight();
                    tooltip.addClass(classes.top);
                } else {
                    tooltip.removeClass(classes.top);
                }
    
                tooltip.css({
                    left: pos.x,
                    top: pos.y
                }).animate({
                    top: "+=10",
                    opacity: 1
                }, 50);
            };
    
            function activate() {
                var self = $(this);
                var message = self.attr("title");
                var tooltip = $("<div class='{0}'></div>".format(classes.tooltip));
    
                if (!message) {
                    return;
                }
                self.removeAttr("title");
                tooltip.css("opacity", 0).html(message).appendTo("body");
    
                var reload = function() { // respec tooltip's size and position.
                    init(self, tooltip);
                };
                reload();
                $(window).resize(reload);
    
                var remove = function () {
                    tooltip.animate({
                        top: "-=10",
                        opacity: 0
                    }, 50, function() {
                        $(this).remove();
                    });
    
                    self.attr("title", message);
                };
    
                self.bind("mouseleave", remove);
                tooltip.bind("click", remove);
            };
    
            return this.each(function () {
                var self = $(this);
                self.bind("mouseenter", activate);
            });
        };
    
        $.tooltip = function() {
            return $("[rel~=tooltip]").tooltip();
        };
    })(jQuery, window);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the jQuery Validate plugin to only display the validation messages only upon
I want to display and iframe into a jquery ui dialog. This iframe needs
I want the maxlength validation of jQuery validate to display an error message like
I want to display the error message generated by jQuery validation plugin at a
Using this jQuery validation plugin. http://www.benjaminkeen.com/software/rsv/jquery/index.php I want to validate a checkbox group with
I am working on a jquery mobile app, where i want to display the
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
In the header of the django admin, I want display a link. This link
I want to display result of this javascript in a label control on my
I want to validate my date field in mm-dd-yyyy format using jquery validation plugin.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.