Is there a way to dynamically ajax add elements through jquery chosen plugin?-open source projects harvesthq/chosen
I am trying to use “Chosen” 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.
Reloading the options is fairly simple:
// In ajax response
var newOption = new Option("Text", __value__);
$("#tagSelection").append(newOption);
$("#tagSelection").trigger("liszt:updated");
However, I don’t know how to make “Chosen” plugin pick this as the value. I would love to do something like
$("#tagSelection").trigger("liszt:select:__value__");
or something similar.
Any suggestions?
(ps: I am trying to build a “tagging” plugin based on chosen. So, if the tag being typed doesn’t exist, it will add it to the server and then select it straight away.)