bootstrap-select icon indicating copy to clipboard operation
bootstrap-select copied to clipboard

Cannot read property 'valHooks' of undefined

Open leonelpena opened this issue 9 years ago • 10 comments

Hello,

I installed the plugin throw npm and added the html tags to the header:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.min.js"></script>

However I get the error:

Uncaught TypeError: Cannot read property 'valHooks' of undefined
    at bootstrap-select.min.js:7
    at bootstrap-select.min.js:8
    at bootstrap-select.min.js:7
    at bootstrap-select.min.js:7

does anybody know about this?

Regards.

leonelpena avatar Dec 26 '16 20:12 leonelpena

I'm having the same issue.

the-codetrane avatar Dec 28 '16 18:12 the-codetrane

What version of jQuery are you using? You need to load jQuery before bootstrap-select.min.js.

caseyjhol avatar Dec 29 '16 23:12 caseyjhol

I was able to resolve this be removing turbolinks. Thanks for your help!

the-codetrane avatar Jan 07 '17 16:01 the-codetrane

I have the same question,I can't think how you solved the problem.

stajason avatar Oct 23 '17 09:10 stajason

@caseyjhol is right, even if rails-assets.org says something different.

This order works for a Rails 4.2.5 app (w/ Turbolinks)

# app/assets/javascripts/application.js

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap-select
//= require turbolinks
//= require bootstrap

hotsen avatar Dec 02 '17 16:12 hotsen

I am using this library in React, and I have the same problem of valHooks and options are not styled as shown in docs, How to solve for React now? as mentioned in https://github.com/snapappointments/bootstrap-select/issues/1875, how to add bootstrap-select.js, it's already added in node_modules when installed!

denishrana09 avatar May 02 '19 13:05 denishrana09

I am having the same issue in prod, but my test is fine. They are both hosted on the same server. The only difference I can think of is that Prod has cloudflare enabled.

Im using php, with no real framework. I tried switching from the min version to an uncompressed version. I will update here if I find a solution.

Update: I had two references to the js. Once I removed one I was fine.

thorst avatar Sep 09 '19 14:09 thorst

I have solve the issue on my side by adding defer into the script.

<link defer rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap-select.min.css">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap-select.min.js"></script>

I hope this helps you all to solve the issue!

geralddevelop avatar Oct 07 '20 11:10 geralddevelop

I I am using laravel 9 and after I mix the file with npm, selectpicker works, but even though it works, I still get the same error. do you have a solution? jquery sees var $. because I added a jquery line in front of where it gave the error and it prints it to the console with success. I have no idea what jquery turbo is. Do I need to install this extra in Laravel?

note: my jquery version is 3.6.0

sevket-karayilan avatar Apr 27 '22 20:04 sevket-karayilan

More info when to use defer as in @GeraldHeng answer on stack. Use in js is <cool_script>.setAttribute("defer", "defer"). Loading jquery before select made it for me, both scripts at the end of body before </body>.

tik9 avatar Sep 09 '22 08:09 tik9