Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is throwing a jQuery error "Uncaught TypeError: $(...).find(...).off(...).popover is not a function" when there are no popovers enabled and a page is updated via AJAX - currently experiencing it where I'm using the Views Load More button:
detach: function (context) {
// Destroy all popovers.
$(context).find('[data-toggle="popover"]')
.off('click.drupal.bootstrap.popover')
.popover('destroy');
}
The find function returns nothing and trying to call ".off" or ".popover" on the empty array throws the error. I tried turning off popovers from the sub theme level but it still breaks.
Should it be using something like the attach function like this to iterate the array so it doesn't work on empty arrays? (Not tested, just asking for suggestions)
var elements = $(context).find('[data-toggle=popover]').toArray();
for (var i = 0; i < elements.length; i++) {
var $element = $(elements[i]);
$element.off('click.drupal.bootstrap.popover')
.popover('destroy');
}
Comment | File | Size | Author |
---|---|---|---|
#13 | recent_update_for-2883951-8.x-3.x-13.patch | 1.51 KB | markhalliwell |
#13 | recent_update_for-2883951-7.x-3.x-13.patch | 1.32 KB | markhalliwell |
Comments
Comment #2
nsciaccaComment #3
nsciaccaAttaching proposed patch that checks the settings and uses the same loop as the attach function
Comment #4
nsciaccaComment #5
markhalliwellThis change is not needed.
Comment #6
nsciaccaIf I leave the checkbox for enable Popovers checked for the theme (which was the original setting before I tried to turn it off to fix the error), but there are no items with "data-toggle=popover" on the page it will throw the error, so I think it's still needed. This is with jQuery 1.10.2.
Comment #7
markhalliwellNo, it threw the error
Uncaught TypeError: $(...).find(...).off(...).popover is not a function
, which is just saying that the$.fn.popover
method doesn't exist.jQuery's
$.fn.find
method will return a valid jQuery object, even if there's no elements. Thus, any subsequent method calls like$.fn.off
will simply be ignored.Placing the if statement at the top and checking the settings should sufficiently cover whether the detach handler should be executed.
Comment #8
nsciaccaGot it, thanks. I traced it back to my theme not using the full bootstrap js library via "bootstrap_cdn"- we selectively include the bootstrap js files we're using, so the popover is not included and $.fn.popover is undefined. So I should be good with just disabling the option in the theme. New patch attached with what you originally suggested without the for loop.
Comment #9
markhalliwellHm, well I suppose adding
|| !$.fn.popover
to the if statement would be prudent as well then.Comment #10
drupal_simply_amazing CreditAttribution: drupal_simply_amazing commentedPatch #3 is also working for me. In my case the error shows when you have a views blocks with expose filter on it.
Comment #11
DanielVezaPatch in #3 solved the problem for us too. Setting this to RTBC since it's had 2 reports of success. Happy for it to be changed back if you still think there may need to be more work done as per #9
Comment #12
dadderley CreditAttribution: dadderley as a volunteer commented@nsciacca - Thank you
I just encountered this with the image module upload functionality.
Trying to upload an image resulted in this error message:
Patch in #3 solved the problem.
Comment #13
markhalliwellOk. I went ahead and fixed #9 as well as the code in HEAD (8.x-3.x).
Comment #16
sonnguyenhcm CreditAttribution: sonnguyenhcm as a volunteer commentedI had the same issue, when a page is loaded via ajax
In Appearance, it says
"Elements that have the data-toggle="popover" attribute set will automatically initialize the popover upon page load"
So I just needed to enable popover.js in theme_name.info. Then It was working.
Comment #17
GuillaumeDuveauGreat, thanks for the fix in #13 :)