2

I'm working in ServiceNow's Istanbul version and am running into some issues incorporating the bootstrap popover into one of my widgets. The widget currently has fullCalendar dependency and renders a calendar with important dates. I wanted to incorporate a popover that a user can click on to get more information, however it doesn't seem to work correctly. I've initialized the popover with the following jquery:

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover(); 

    $('.popover-dismiss').popover({
        trigger: 'focus'
        })
});
</script>  

My HTML looks like this:

<span  class="list-group-item" ng-repeat="item in c.dates | orderBy:'date' track by $index" ng-if="item.displayList=='true' && item.futureDate">
        <li class="rowflex" style="list-style: none;">
          <div class="colflex">              
                <strong><i class="fa fa-calendar" aria-hidden="true"></i>&nbsp; {{item.date}}</strong>
            <p>{{item.date_name}}</p>
          </div>
          <a tabindex="0" class="glyphicon glyphicon-question-sign" role="button" data-toggle="popover" data-placement="right" data-trigger="focus" title="test" data-content="test"/>  
        </li>
      </span>

Currently when i hover over the question mark glyphicons I can see "test", but when I click on it, nothing happens.

enter image description here

When I look in the console, I get this error message, but I'm unfamiliar with how to fix it:

enter image description here

Any suggestions?

Thanks!

Dave
  • 1,257
  • 2
  • 27
  • 58
  • Do you have the script for bootstrap popover loaded? – Oluwafemi Sule Aug 08 '17 at 19:17
  • no i do not, i have it in the HTML within tags – Dave Aug 08 '17 at 19:19
  • You should add `` right after the script markup that loads jQuery. – Oluwafemi Sule Aug 08 '17 at 19:23
  • Thanks so I tried this for my dependencies in this order, but not only did the popover not work, the calendar also disappeared: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js, http://getbootstrap.com/dist/js/bootstrap.min.js, https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js, https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.js – Dave Aug 08 '17 at 21:25
  • What bootstrap version are you using? – Oluwafemi Sule Aug 08 '17 at 21:40
  • Hi Oluwafemi, I really don't know what version of bootstrap comes with ServiceNow, but I've used the bootstrap popover in other widgets and it works fine. I'm not sure why it doesn't work for this one in particular. I've also cloned this widget, taken out EVERYTHING related to the fullcalendar including all the dependencies and it still refuses to work. Not really sure what is going on here... – Dave Aug 08 '17 at 22:33

2 Answers2

1

After many attempts to make it work, I found the solution. You need to use Timeout.

Use one of the following options in your widget..

Option #1 - Client Script (Client Controller)

function ($scope, spUtil, $sce, $rootScope, $timeout) {
    $(document).ready(function(){
        setTimeout(function(){
            $('[data-toggle="popover"]').popover();
        },500);
    });
}

Option #2 - Link Function

function() {
    $(document).ready(function(){
        setTimeout(function(){
            $('[data-toggle="popover"]').popover();
        },500);
    });
}

Sample: Popover sample

0

In general with Service Portals, you want to avoid direct jQuery calls and instead use Angular. The error you're seeing is probably from that.

You'll want to look at BootstrapUI for Bootstrap + Angular to have a reference for some of the APIs you can use here, but may still be hit-or-miss.

Leverage the $uibModal service to open your modal.

A great resource I've used is https://serviceportal.io, in particular for your case https://serviceportal.io/modal-windows-service-portal/.

I've tested their example on our Istanbul instance and it worked. To summarize that post, here is what you may want to try for your case.

HTML Template

<span class="list-group-item" ng-repeat="item in c.dates | orderBy:'date' track by $index" ng-if="item.displayList=='true' && item.futureDate">
    <li class="rowflex" style="list-style: none;">
        <div class="colflex">              
            <strong><i class="fa fa-calendar" aria-hidden="true"></i>&nbsp; {{item.date}}</strong>
            <p>{{item.date_name}}</p>
        </div>
        <a tabindex="0" class="glyphicon glyphicon-question-sign" role="button" data-toggle="popover" data-placement="right" data-trigger="focus" title="test" data-content="test" ng-click="c.openModal()" />  
    </li>
</span>

<script type="text/ng-template" id="modalTemplate">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">Modal Window</h4>
        </div>
        <div class="panel-body wrapper-xl">
            Hello
        </div>
        <div class="panel-footer text-right">
            <button class="btn btn-primary" ng-click="c.closeModal()">${Close Modal}</button>
        </div>
    </div>
</script>

Client Script

function($uibModal, $scope) {
    var c = this;

    c.openModal = function() {
        c.modalInstance = $uibModal.open({
            templateUrl: 'modalTemplate',
            scope: $scope
        });
    }

    c.closeModal = function() {
        c.modalInstance.close();
    } 
}
Kirk
  • 16,182
  • 20
  • 80
  • 112
  • Thanks Kirk, I gave that a try and it still doesn't work unfortunately. – Dave Aug 11 '17 at 13:51
  • Is there a new error? For just a random shot, go to https://instance.service-now.com/cache.do *(replace instance with yours)* to clear your server cache. I've seen your original error caused by cache issues before. – Kirk Aug 11 '17 at 15:13