{"id":8023,"date":"2015-11-21T13:42:27","date_gmt":"2015-11-21T13:42:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/21\/select2-dropdown-dynamically-add-remove-and-refresh-items-from-open-source-projects-select2-select2\/"},"modified":"2022-08-30T15:03:03","modified_gmt":"2022-08-30T15:03:03","slug":"select2-dropdown-dynamically-add-remove-and-refresh-items-from-open-source-projects-select2-select2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/21\/select2-dropdown-dynamically-add-remove-and-refresh-items-from-open-source-projects-select2-select2\/","title":{"rendered":"Select2 Dropdown Dynamically Add, Remove and Refresh Items from-open source projects select2\/select2"},"content":{"rendered":"<p>This drives me crazy! Why cant Select2 implement clear methods or examples on their page how to do simple CRUD manipulation on Select2 \ud83d\ude42<\/p>\n<p>i have a select2 which gets data from a ajax call.<\/p>\n<pre><code>\n\n$(\"#valueg\").select2({\n             data: conferences,\n             allowClear: true,\n             initSelection: function (element, callback) {\n                            var data = { id: element.val(), text: element.val() };\n                            callback(data);\n                        }\n}).on(\"change\", function (e) {\n \/\/ show data in separate div when item is selected               \n});\n<\/code><\/pre>\n<p>Can some one provide a clear method how to delete and add an item from the Select2.<\/p>\n<p>For example:<\/p>\n<p>I add an item via ajax call to db, and just want to append an option to Select2 and set it as selected.<\/p>\n<p>I remove an item via ajax to db, and want to remove an option from Select2 and have no option selected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This drives me crazy! Why cant Select2 implement clear methods or examples on their page how to do simple CRUD manipulation on Select2 \ud83d\ude42 i have a select2 which gets data from a ajax call. $(&#8220;#valueg&#8221;).select2({ data: conferences, allowClear: true, initSelection: function (element, callback) { var data = { id: element.val(), text: element.val() }; callback(data); [&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-8023","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8023","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=8023"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8023\/revisions"}],"predecessor-version":[{"id":8687,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8023\/revisions\/8687"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}