1

I've been trying to get Tippy.js' nested tooltip feature working but haven't had luck so far.

the following lines are placed outside jQuery's Document ready function:

tippy.setDefaultProps({
    appendTo: function () {
        return document.querySelector('.responseBody')
    }
})

popperOptions: { strategy: 'fixed' };

tippy.delegate('.responseBody', {
    target: '.tooltip'
});

the tooltip content is being added dynamically based on an extract from ajax response and the ajax function is the following:

function _loadLaunchPad(iSMHost, iSMPort, urlExtension) {

    var _serverName = $('#serverName option:selected').text();
    var _addOnSelect = $('#addOnSelect option:selected').text();
    var _consoleCmdExprValue = $('#consoleCmdExprValue').val();
    var dataString = '{ "serverSelection" : "' + _serverName + '", "operationSelection" : "' + _addOnSelect + '", "commandSelection" : "' + _consoleCmdExprValue + '"}';
    var stringToSend = "   <img class='preLoader' src='images/preloader.gif' title = 'Processing request'/>";
    const _toolTipContentHeader = ' <div>' +
        '     <strong>Server Name &emsp;&emsp;&emsp;<span class="tooltip" data-title="<strong>hey</strong>" style="color: aqua">%HDRITEM0%</span></strong><br />' +
        '     <strong>Server IP Address &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM1%</span></strong><br />' +
        '     <strong>Server #Processors &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM2%</span></strong><br />' +
        '     <strong>Version &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM3_1%</span></strong><br />' +
        '     <strong>Build Ref &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM3_2%</span></strong><br />' +
    //  '     <strong>Build Date &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM3_3%</span></strong><br />' +
        '     <strong>Configs Count &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM4%</span></strong><br />' +
        '     <strong>Master Config &emsp;&emsp;&emsp;<span style="color: aqua">%HDRITEM5%</span></strong><br />' +
        ' </div>';

    const _toolTipContentLine = ' <div>' +
        '     <strong>Server Name &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM0%</span></strong><br />' +
        '     <strong>Config Process ID &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM1%</span></strong><br />' +
        '     <strong>Config Status &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM2%</span></strong><br />' +
        '     <strong>Config Java Version &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM3%</span></strong><br />' +
        '     <strong>Version &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM4_1%</span></strong><br />' +
        '     <strong>Build Ref &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM4_2%</span></strong><br />' +
    //  '     <strong>Build Date &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM4_3%</span></strong><br />' +
        '     <strong>iBSE Port (If Enabled) &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM5%</span></strong><br />' +
        '     <strong>Master Config &emsp;&emsp;&emsp;<span style="color: aqua">%LNITEM6%</span></strong><br />' +
        '     <strong>Registry &emsp;&emsp;&emsp;<span style="color: aqua"><a href="%LNITEM7%" target="_blank">Here</a></span></strong><br />' +
        '     <strong>Blue &emsp;&emsp;&emsp;<span style="color: aqua"><a href="%LNITEM8%" target="_blank">Here</a></span></strong><br />' +
        '     <strong>Runtime &emsp;&emsp;&emsp;<span style="color: aqua"><a href="%LNITEM9%" target="_blank">Here</a></span></strong><br />' +
        ' </div>';

    $.ajax({
        type: "POST",
        url: `http://${iSMHost}:${iSMPort}/${urlExtension}`,
        data: dataString,
        timeout: 60000 * 30, //60000 milliseconds * 30 = 30 minutes
        async: true,
        contentType: "application/json",
        cache: false,
        beforeSend: function () {
            $(".terminal .top").addClass('color-change-5x');
            $('.terminal .responseBody').html("");
        },
        success: function (result) {
            
            if (_addOnSelect == 'ConfigsList') {
                var h1 = $('<h1 class="responseTitleText">Launch Pad</h1>')
                var tabDiv = $('<div id="tabsID"></div>')
                var prodTab = $('<div class="tab-container" data-tab-index="0"></div>');
                var testTab = $('<div class="tab-container" data-tab-index="1" style="display:none;"></div>');
                $('.terminal .responseBody').append(h1);
                $('.terminal .responseBody').append(prodTab);
                $('.terminal .responseBody').append(testTab);
                for (var i = 0; i < result.length; ++i) {
                    var div = $('<div>'), ulForTest = $('<ul>'), ulForProd = $('<ul>');
                    var _tempHeaderItem = result[i];
                    var _tempInstanceFlag = (_tempHeaderItem.host).split(':')[1];
                    var _tempHostEnvironment = (_tempHeaderItem.host).split(':')[0]
                    _tempHostEnvironment = ((/p.me.com$/).test(_tempHostEnvironment)) ? 'Prod' : 'Test';
                                        
                    var replacementsForHDR = {
                        "%HDRITEM0%": _nvl(_tempHeaderItem.host.replace('.me.com', '')),
                        "%HDRITEM1%": _nvl(_tempHeaderItem.serverIP),
                        "%HDRITEM2%": _nvl(_tempHeaderItem.processorsCount),
                        "%HDRITEM3_1%": _nvl(_tempHeaderItem.configs[0].Version),
                        "%HDRITEM3_2%": _nvl(_tempHeaderItem.configs[0].Build),
                    //  "%HDRITEM3_3%": _nvl(_tempHeaderItem.configs[0].BuildDate),
                        "%HDRITEM4%": _nvl(('Active: ' + _tempHeaderItem.activeConfigsCount + '/ Inactive: ' + _tempHeaderItem.inActiveConfigsCount)),
                        "%HDRITEM5%": _nvl(_tempHeaderItem.master)
                    };

                    var _toolTipContentHeaderInstance = _toolTipContentHeader.replace(/%\w+%/g, function (all) {
                        return replacementsForHDR[all] || all;
                    });

                    _tempInstanceFlag = (_tempInstanceFlag == '19') ? '1st' : (_tempInstanceFlag == '29') ? '2nd' : (_tempInstanceFlag == '39') ? '3rd' : (_tempInstanceFlag == '49') ? '4th' : '1st?';
                    if(_tempHostEnvironment == 'Prod'){
                        ulForProd.append("<li class='tooltip' data-title='" + _toolTipContentHeaderInstance + "'>" + ((_tempHeaderItem.host).split('.')[0]).replace(".me.com", "") + " " + _tempInstanceFlag + "</li>")
                    }else{
                        ulForTest.append("<li class='tooltip' data-title='" + _toolTipContentHeaderInstance + "'>" + ((_tempHeaderItem.host).split('.')[0]).replace(".me.com", "") + " " + _tempInstanceFlag + "</li>")
                    }
                    
                    for (var j = 0; j < _tempHeaderItem.configs.length; ++j) {
                        var _tempLineItem = _tempHeaderItem.configs[j];
                        var replacementsForLN = {
                            "%LNITEM0%": _nvl(_tempHeaderItem.host.replace('.me.com', '')),
                            "%LNITEM1%": _nvl(_tempLineItem.processID),
                            "%LNITEM2%": _nvl(_tempLineItem.status),
                            "%LNITEM3%": _nvl(_tempLineItem.javaVersion),
                            "%LNITEM4_1%": _nvl(_tempLineItem.Version),
                            "%LNITEM4_2%": _nvl(_tempLineItem.Build),
                        //  "%LNITEM4_3%": _nvl(_tempLineItem.BuildDate),
                            "%LNITEM5%": _nvl(((_tempLineItem.ibsePort.length > 0) ? _tempLineItem.ibsePort : 'NA')),
                            "%LNITEM6%": _nvl(_tempHeaderItem.master),
                            "%LNITEM7%": _nvl('http://' + _tempHeaderItem.host + '/' + _tempLineItem.config + '&filter=on'),
                            "%LNITEM8%": _nvl('http://' + _tempHeaderItem.host + '/yes?configuration=' + _tempLineItem.config),
                            "%LNITEM9%": _nvl('http://' + _tempHeaderItem.host + '/yes?configuration%7D_' + _tempLineItem.config)
                        };

                        var _toolTipContentLineInstance = _toolTipContentLine.replace(/%\w+%/g, function (all) {
                            return replacementsForLN[all] || all;
                        });

                        if(_tempHostEnvironment == 'Prod'){
                            div.append(ulForProd.append("<li class='tooltip' data-title='" + _toolTipContentLineInstance + "'>" + _tempLineItem.config + "</li>"));
                            $('#tabLink').show();
                            $('.terminal .responseBody .tab-container[data-tab-index=0]').append(div.addClass('tracking-in-expand-fwd'));
                        }else{
                            div.append(ulForTest.append("<li class='tooltip' data-title='" + _toolTipContentLineInstance + "'>" + _tempLineItem.config + "</li>"));
                            $('#tabLink').show();
                            $('.terminal .responseBody .tab-container[data-tab-index=1]').append(div.addClass('tracking-in-expand-fwd'));
                        }                                               
                    }
                }
            }

            tippy('.tooltip', {
                theme: 'custom',
                content: function (reference) {
                    const htmlContent = reference.getAttribute('data-title');
                    return htmlContent;                 
                },
                interactive: true,
                allowHTML: true,
                multiple: true
            });

            popperOptions: { strategy: 'fixed' };
        },
        error: function (x, t, m) {
            $('.terminal .responseBody').html("<p class='error fade-in-fwd'>Something went wrong at the server. Thats all I know! :-(</p>");
        },
        complete: function (x, t, m) {
            $('.terminal .title').html('response pane');
            $(".terminal .top").removeClass('color-change-5x');
        }
    });
    return false;
}

the relevant CSS styling info

.tippy-box[data-theme~="custom"] span {
  float: right;
  
}

.tippy-box[data-theme~="custom"] {
  width: max-content;
}

Owing to the complexity of the application, I couldn't create a repro on a fiddle/etc. The first tooltip gets displayed well, while the nested does not get displayed.

result:

enter image description here

Any help would be much appreciated.

If the nested tooltip is invoked using data-tippy-content with html, the value gets displayed but the HTML gets displayed raw, meaning, HTML tags appear as-is.

Srii
  • 543
  • 3
  • 7
  • 20

0 Answers0