{"id":8168,"date":"2022-03-30T17:15:00","date_gmt":"2022-03-30T17:15:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/28\/trouble-with-a-semantic-ui-jquery-dropdown-button-using-a-block-component-in-ember-js-open-source-projects-semantic-org-semantic-ui\/"},"modified":"2022-08-30T15:42:24","modified_gmt":"2022-08-30T15:42:24","slug":"trouble-with-a-semantic-ui-jquery-dropdown-button-using-a-block-component-in-ember-js-open-source-projects-semantic-org-semantic-ui","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/03\/30\/trouble-with-a-semantic-ui-jquery-dropdown-button-using-a-block-component-in-ember-js-open-source-projects-semantic-org-semantic-ui\/","title":{"rendered":"Trouble with a Semantic UI\/jQuery dropdown button using a block component in Ember JS-open source projects Semantic-Org\/Semantic-UI"},"content":{"rendered":"<p>I&#8217;m having difficulty getting a Semantic UI (1.12.2) jQuery dropdown button located inside a block component to work in Ember JS (1.11.0). I think I understand the run loop issues with binding jQuery to elements in Ember but in this case I think something nuanced is happening that I am not aware of.<\/p>\n<p>I have a template that calls my component like this:<\/p>\n<pre><code>{{#sui-button-dropdown colour=\"black\" icon=\"retweet\" text=\"Change Status\"}}\n    {{#each status in applicationStatuses}}\n        \n            \n            {{status.description}}\n        \n    {{\/each}}\n{{\/sui-button-dropdown}}\n<\/code><\/pre>\n<p>My component js code is as follows:<\/p>\n<pre><code>import Ember from 'ember';\n\nexport default Ember.Component.extend({\n    didInsertElement: function() {\n        Ember.run.scheduleOnce('afterRender', this, function() {\n            this.$().dropdown({action: 'select'});\n        });\n    },\n    actions: {\n        changeStatus: function() {\n            this.$().dropdown('toggle');\n        }\n    }\n});\n<\/code><\/pre>\n<p>And my component .hbs view is:<\/p>\n<pre><code>\n    \n    \n    {{text}}\n    \n        {{yield}}\n    \n\n<\/code><\/pre>\n<p>The &#8220;applicationStatuses&#8221; binding is pulled in via ember-data from an API asynchronously and so is a promise. I have placed the jQuery binding to .dropdown() inside a &#8220;didInsertElement&#8221; function and in order to make sure the promise has returned and the list has been rendered it is also scheduled for the next iteration of the run loop &#8220;afterRender&#8221;.<\/p>\n<p>However, when I click the dropdown button no dropdown appears. There are no errors and the dropdown() function is definitely being called upon the dropdown button element as I have checked it. I suspect that I have missed something and the dropdown() jQuery method is binding before the AJAX call that returns the &#8220;applicationStatuses&#8221; collection, meaning the list hasn&#8217;t been populated when it runs.<\/p>\n<p>If I take all of this out of the component and create it all in the parent controller\/template the button dropdown works but components are the way to go so I&#8217;d appreciate any help anyone can offer.<\/p>\n<p>Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m having difficulty getting a Semantic UI (1.12.2) jQuery dropdown button located inside a block component to work in Ember JS (1.11.0). I think I understand the run loop issues with binding jQuery to elements in Ember but in this case I think something nuanced is happening that I am not aware of. I have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-8168","post","type-post","status-publish","format-standard","hentry","category-semantic"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8168","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=8168"}],"version-history":[{"count":2,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8168\/revisions"}],"predecessor-version":[{"id":8726,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8168\/revisions\/8726"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}