4

I am noticing an error when I trigger the .popover('dispose'); function the error happens when I scroll up and down page and it slows my page right down. The function behaves as it should and dismisses the popover but this is the error Uncaught (in promise) TypeError: Cannot read property 'template' of null popover.js ]1]1

My function

$('#country').focus(function (e) {
    e.preventDefault();
    $("#country").popover('hide');
    $("#country").popover('disable');
    $("#country").popover('dispose');
});

I have implemented a dynamic popover and I needed to add in a function similar to the above on focus the input field as the popover message keeps appearing after its done its job.

var allCountries = ['a', 'b', 'c', ...];
var mispelledCountryMsg = "misspelled error message...";

$('#country').focusout(function (e) {
    e.preventDefault();
    $.each(allCountries, function (x) {
       if (inp.value !== allCountries[x]) {
            $('[data-toggle="popover"]').popover();
            $('#country').attr('data-content', mispelledCountryMsg).popover('show');
            disableFormFields();
       } 
    });
});
Mahyar Mottaghi Zadeh
  • 1,178
  • 6
  • 18
  • 31
roshambo
  • 2,624
  • 6
  • 31
  • 54

1 Answers1

0

Try to use {'trigger': 'manual'}

$('[data-toggle="popover"]').popover({'trigger': 'manual'});
nzy
  • 11
  • 1