select2
検索ボックスの代わりに使用しています。
ここでは、このような国の値をロードするために使用しています
$("#countries").select2({
multiple: true,
tags:["India", "Japan", "Australia","Singapore"],
tokenSeparators: [","]
});
保存ボタンを押すと、サーバーに適切に送信されます。ここで問題は、サーバーに保存した後に国フィールドを変更したい場合、保存された値を国フィールドにロードする方法です。
これは、サーバーからデータを取得する方法です
$.getJSON('/dataprovider?data=fetchCountriesForm', function(opts) {
//the opts here contains the json values of the countries.
//what code should be written here to load the values in $('#countries).select2();
//user can add some more countries or can remove the previously added countries.
}