Hi guys,

sub-theming like in https://drupal-bootstrap.org/api/bootstrap/docs%21Sub-Theming.md/group/s... I'm getting some weird issues:

1) if popover are active, I can see the following in the console:

drupal.js?v=8.3.2:59 Uncaught TypeError: Cannot read property 'Constructor' of undefined
at Object.attach (popover.js?oqgtwk:40)
at Object.Drupal.attachBehaviors (drupal.js?v=8.3.2:160)
at drupal.init.js?v=8.3.2:17
at HTMLDocument.t (ready.min.js?v=1.0.8:4)

so looks like somehow popover plugin is not being instantiated properly.

2) collapsed menu in mobile view has no click event attached. Thought it was because popover was causing trouble while breaking, but even disabling it that event is not happening.

Does anyone faced the same? Any hint on how to fix it or at least where to start debugging it?

Thanks in advance!

Comments

arm4 created an issue. See original summary.

markhalliwell’s picture

Category: Bug report » Support request
Priority: Major » Minor
Status: Active » Closed (works as designed)
Issue tags: -javascript error

This just means that your sub-theme doesn't have or load the framework's popover.js file (or bootstrap.min.js, if it's bundled together).

Disabling this via the theme settings is exactly the way to mitigate this error because it doesn't exist. If it does exist, then you can enable.

By default, the base theme uses the CDN (which uses the bundled JS and has popovers included).

If you're building a custom theme, then it's your responsibility to install the necessary framework plugins.

arm4’s picture

ooooouch .... i forgot to uncomment them in .libraries.yml

thanks markcarver!

asirjacques’s picture

Hi there,

I've similar issue.

I'm creating a sub-theme of Bootstrap theme 8.x-3.5 . In my custom sub-theme info.yml file I've added my custom libraries. My custom sub-theme library has a dependency on bootstrap/theme library. This is working great, I can see that popover.js is loaded from bootstrap/theme but somehow it keeps giving me this error:

drupal.js?v=8.3.2:59 Uncaught TypeError: Cannot read property 'Constructor' of undefinedattach @ popover.js?or8fla:40Drupal.attachBehaviors @ drupal.js?v=8.3.2:160(anonymous function) @ drupal.init.js?v=8.3.2:17t @ ready.min.js?v=1.0.8:4
drupal.js?v=8.3.2:59 Uncaught TypeError: Cannot read property 'Constructor' of undefinedattach @ tooltip.js?or8fla:38Drupal.attachBehaviors @ drupal.js?v=8.3.2:160(anonymous function) @ drupal.init.js?v=8.3.2:17t @ ready.min.js?v=1.0.8:4

I've the same issue with tooltip.

In the source I can see that it is being loaded:

<script src="/core/assets/vendor/jquery/jquery.min.js?v=2.2.4"></script>
<script src="/core/assets/vendor/jquery-once/jquery.once.min.js?v=2.1.1"></script>
<script src="/core/misc/drupalSettingsLoader.js?v=8.3.2"></script>
<script src="/core/misc/drupal.js?v=8.3.2"></script>
<script src="/core/misc/drupal.init.js?v=8.3.2"></script>
<script src="/themes/bootstrap/js/drupal.bootstrap.js?or8fp7"></script>
<script src="/themes/bootstrap/js/attributes.js?or8fp7"></script>
<script src="/themes/bootstrap/js/theme.js?or8fp7"></script>
<script src="/themes/bootstrap/js/misc/form.js?or8fp7"></script>
<script src="/themes/bootstrap/js/misc/ajax.js?or8fp7"></script>
<script src="/themes/bootstrap/js/modal.js?or8fp7"></script>
<script src="/themes/bootstrap/js/misc/dialog.js?or8fp7"></script>
<script src="/themes/custom/js/jqBootstrapValidation.js?or8fp7"></script>
<script src="/themes/custom/js/custom.js?or8fp7"></script>
<script src="/themes/custom/bootstrap/assets/javascripts/bootstrap/scrollspy.js?or8fp7"></script>
<script src="/themes/bootstrap/js/popover.js?or8fp7"></script>
<script src="/themes/bootstrap/js/tooltip.js?or8fp7"></script>

Any idea, what am I missing ?

Thanks.

asirjacques’s picture

Ok, my mistake.

I did not know that the sub theme did not inherited the parent theme configuration settings. Therefore the reason I had 2 popover.js and tooltip.js file loaded was that:

1 - Enable Bootstrap Popovers and Enable Bootstrap Tooltips was check in Appearance > My custom theme > Javascript.
2 - I add copy pasted the file THEMENAME.libraries.yml that contain the following entry:

bootstrap-scripts:
  js:
    bootstrap/assets/javascripts/bootstrap/affix.js: {}
    bootstrap/assets/javascripts/bootstrap/alert.js: {}
    bootstrap/assets/javascripts/bootstrap/button.js: {}
    bootstrap/assets/javascripts/bootstrap/carousel.js: {}
    bootstrap/assets/javascripts/bootstrap/collapse.js: {}
    bootstrap/assets/javascripts/bootstrap/dropdown.js: {}
    bootstrap/assets/javascripts/bootstrap/modal.js: {}
    bootstrap/assets/javascripts/bootstrap/tooltip.js: {}
    bootstrap/assets/javascripts/bootstrap/popover.js: {}
    bootstrap/assets/javascripts/bootstrap/scrollspy.js: {}
    bootstrap/assets/javascripts/bootstrap/tab.js: {}
    bootstrap/assets/javascripts/bootstrap/transition.js: {}

So, I ended up having popover and tooltips loaded twice.

My Solution:

1 - Remove tooltips.js and popover.js from the THEMENAME.libraries.yml
2 - in mycustomtheme.info.yml, add

libraries-override:
  bootstrap/tooltip:
    js:
      js/tooltip.js: bootstrap/assets/javascripts/bootstrap/tooltip.js
  bootstrap/popover:
    js:
      js/popover.js: bootstrap/assets/javascripts/bootstrap/popover.js

Warning:
The remaining issue is that popover.js gets loaded before tooltip.js giving the following error:

popover.js?orhgcf:20 Uncaught Error: Popover requires tooltip.js

If I go to bootstrap.libraries.yml and add weight:-1 to tooltip library it works because the tooltip.js is laoded before popover.js.

How can solve this without touching the bootstrap parent theme ?

Thanks.

jbfelix’s picture

Same issue, any news ?

jonraedeke’s picture

@asirjacques I thought I was having the same issue, but I realized that
/themes/contrib/bootstrap/js/tooltip.js
is NOT that same file as
/themes/custom/mytheme/bootstrap/assets/javascripts/bootstrap/tooltip.js

The child theme does inherit the parent libraries. /themes/contrib/bootstrap/js/tooltip.js just contains the settings and Drupal-specific code. So you need both files for the plugin to work. Following the README for the subtheme will load both properly. Alternatively, you can load the whole bootstrap library via CDN, which will contain the tooltip js you need.

thanhpha’s picture

Component: Starterkit (SASS) » Code

@asirjacques solution works for me!!