Search code examples
javascriptjoomlatooltip

Tooltips in Joomla containing HTML


I created a component using Component Creator for Joomla 3.X

The problem is that on the site the tooltips show html code. For example:

<strong>Title</strong><br/>Description

Instead, on the administrator they are displayed properly:

Title

Description

I was reviewing the documentation here and here, and it seems that it is possible to define the output format when calling the tooltip function but there are no calls inside the component to that function. The only call I see is JHtml::_('behavior.tooltip'); at the begining of the view file and don't know how to specify the output format.

The site is in this URL:

http://50.87.185.99/colombianadederecho_blank/index.php/administradores-ph/registrarse

Added:

It seems like the code is called when building the label for each field:

<div class="control-group">
    <div class="control-label"><?php echo $this->form->getLabel('document'); ?></div>
    <div class="controls"><?php echo $this->form->getInput('document'); ?></div>
</div>

And it is stored in the title attribute:

title="&lt;strong&gt;Title&lt;/strong&gt;&lt;br /&gt;Description"

So, I think the problem is in the Javascript function, maybe using a .text() jQuery function instead of a .html().

Inspecting the source code I found this, but don't understand why it is not working properly:

window.addEvent('domready', function() {
            $$('.hasTip').each(function(el) {
                var title = el.get('title');
                if (title) {
                    var parts = title.split('::', 2);
                    el.store('tip:title', parts[0]);
                    el.store('tip:text', parts[1]);
                }
            });
            var JTooltips = new Tips($$('.hasTip'), {"maxTitleChars": 50,"fixed": false});
        });

jQuery(document).ready(function() {
    jQuery('.hasTooltip').tooltip({"html": true,"container": "body"});
});

Solution: As @ilias found it was a problem between libraries. I had to disable the bootstrap call in the header using this plugin and call it from the end of the body:

<script src="/site/media/jui/js/bootstrap.min.js" type="text/javascript"></script>

Solution

  • I don't know the code that Component Creator produces, however I assume that the tooltips are like in the administrator views. If this is the case you should check for something like this:

    <button type="submit" class="btn hasTooltip" title="<?php echo JHtml::tooltipText('JSEARCH_FILTER_SUBMIT'); ?>"><i class="icon-search"></i></button>
    

    and enclose the contents of JHtml::tootlipText() in strip_tags().

    Otherwise try to find the line <strong>Title</strong><br/>Description where the tags are shown and enclose it in strip_tags(). For example you might have something that looks like:

    echo $this->escape($item->description);
    

    that should be turned into:

    echo $this->escape(strip_tags($item->description));