{"id":1412,"date":"2022-08-30T15:16:19","date_gmt":"2022-08-30T15:16:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/bootstrap-modal-created-inside-coffeescript-not-working-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:19","modified_gmt":"2022-08-30T15:16:19","slug":"bootstrap-modal-created-inside-coffeescript-not-working-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/bootstrap-modal-created-inside-coffeescript-not-working-collection-of-common-programming-errors\/","title":{"rendered":"bootstrap modal created inside coffeescript not working-Collection of common programming errors"},"content":{"rendered":"<p>My problem in a nutshell is that from within coffeescript implemented jQuery-UI handler, I cannot create and show a bootstrap modal. If I try to show the modal using the standard button approach that is on the bootstrap documentation it works just fine. EDIT 3: This is within a Ruby on Rails 3.2 application using the asset pipeline.<\/p>\n<pre><code>Launch demo modal\n<\/code><\/pre>\n<p>However, when I do this from within a jQuery-UI event handler:<\/p>\n<pre><code>$(\"#my-modal\").modal('show')\n<\/code><\/pre>\n<p>or<\/p>\n<pre><code>$(\"#my-modal\").modal({})\n<\/code><\/pre>\n<p>I get this error:<\/p>\n<pre><code>Uncaught TypeError: Object [object Object] has no method 'modal'\n<\/code><\/pre>\n<p>My html is very standard&#8211;I just used the example html from the bootstrap documentation. I have this coffeescript for the jQuery-UI event handler:<\/p>\n<pre><code>$ -&gt;\n  $(\"#selectable\").selectable(\n    selected: (event, ui) -&gt;\n      $(\"#my-modal\").modal({})\n  )\n<\/code><\/pre>\n<p>EDIT: As this smells of a scope issue I tried monkeying with the -&gt; and =&gt; to see if that changed things but no changes to that made any difference.<\/p>\n<p>EDIT 2: I&#8217;ve validated that the javascript libraries are included in the right order: jquery, jquery-ui, jquery_ujs, and then bootstrap.js. Is it possible that there&#8217;s another library I need to pull in?<\/p>\n<p>I&#8217;ve validated that $(&#8220;#my-modal&#8221;) finds the modal DOM object correctly by doing<\/p>\n<pre><code>console.log $(\"#my_modal\").html()\n<\/code><\/pre>\n<p>I&#8217;m at a loss to understand this. The code looks completely straightforward and simple to me.<\/p>\n<ol>\n<li>\n<p>I finally figured this out and thought I&#8217;d post the answer in case someone else runs into this.<\/p>\n<p>Someone else on our team had brought in Google Analytics using jQuery and that was reintroducing jQuery AFTER bootstrap had injected itself into jQuery, thereby removing bootstrap from the world.<\/p>\n<p>As we&#8217;re in the first stages of our project and our motto is to not try to solve next years problems today, I fired him and we waited out back for him when he left. Of course he&#8217;s my boss so none of that happened.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:11:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>My problem in a nutshell is that from within coffeescript implemented jQuery-UI handler, I cannot create and show a bootstrap modal. If I try to show the modal using the standard button approach that is on the bootstrap documentation it works just fine. EDIT 3: This is within a Ruby on Rails 3.2 application using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1412","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1412"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1412\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}