{"id":7897,"date":"2015-11-07T04:56:35","date_gmt":"2015-11-07T04:56:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/07\/is-there-a-way-to-dynamically-ajax-add-elements-through-jquery-chosen-plugin-open-source-projects-harvesthq-chosen\/"},"modified":"2015-11-07T04:56:35","modified_gmt":"2015-11-07T04:56:35","slug":"is-there-a-way-to-dynamically-ajax-add-elements-through-jquery-chosen-plugin-open-source-projects-harvesthq-chosen","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/07\/is-there-a-way-to-dynamically-ajax-add-elements-through-jquery-chosen-plugin-open-source-projects-harvesthq-chosen\/","title":{"rendered":"Is there a way to dynamically ajax add elements through jquery chosen plugin?-open source projects harvesthq\/chosen"},"content":{"rendered":"<p>I am trying to use &#8220;Chosen&#8221; plugin by harvest (http:\/\/harvesthq.github.com\/chosen\/) and it works for the static set of options I am passing. However, what I want is that whenever anybody types something that is not in the pre-filled options, then it should send that to the server as a new option and on successful response, I want to not only add that to the valid list of options, but also make it select it.<\/p>\n<p>Reloading the options is fairly simple:<\/p>\n<pre><code>\/\/ In ajax response\nvar newOption = new Option(\"Text\", __value__);\n$(\"#tagSelection\").append(newOption);\n$(\"#tagSelection\").trigger(\"liszt:updated\");\n<\/code><\/pre>\n<p>However, I don&#8217;t know how to make &#8220;Chosen&#8221; plugin pick this as the value. I would love to do something like<\/p>\n<pre><code>$(\"#tagSelection\").trigger(\"liszt:select:__value__\"); \n<\/code><\/pre>\n<p>or something similar.<\/p>\n<p>Any suggestions?<\/p>\n<p>(ps: I am trying to build a &#8220;tagging&#8221; plugin based on chosen. So, if the tag being typed doesn&#8217;t exist, it will add it to the server and then select it straight away.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to use &#8220;Chosen&#8221; plugin by harvest (http:\/\/harvesthq.github.com\/chosen\/) and it works for the static set of options I am passing. However, what I want is that whenever anybody types something that is not in the pre-filled options, then it should send that to the server as a new option and on successful response, [&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-7897","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7897","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=7897"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7897\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}