私は、同じアイテムを複数回選択できるようにし、それらの複数のエントリを POST 変数としてサーバーに送信することもできる、choose のバージョンを作成しました。これを行う方法は次のとおりです(かなり簡単だと思います):
(ヒント: これらの行を見つけるには、choose.jquery.js の検索機能を使用します)
変化する:
this.is_multiple = this.form_field.multiple;
に:
this.is_multiple = this.form_field.multiple;
this.allows_duplicates = this.options.allow_duplicates;
変化する:
classes.push("result-selected");
に:
if (this.allows_duplicates) {
classes.push("active-result");
} else {
classes.push("result-selected");
}
変化する:
this.form_field.options[item.options_index].selected = true;
に:
if (this.allows_duplicates && this.form_field.options[item.options_index].selected == true) {
$('<input>').attr({type:'hidden',name:this.form_field.name,value:this.form_field.options[item.options_index].value}).appendTo($(this.form_field).parent());
} else {
this.form_field.options[item.options_index].selected = true;
}
次に、 を呼び出すときchosen()
に、必ず次のallows_duplicates
オプションを含めてください。
$("mySelect").chosen({allow_duplicates: true})