I adapted some javascript to work with jquery “select 2” plugin in order to duplicate the selected fields to another part of the form. The only issue is that I am not able to get this to function with the new version of "Select 2" (v.4.0.3). Apparently some methods have been deprecated in the new version and this breaks my code.
Does anyone have insight how I may be able to duplicate form inputs with the latest version?
Here is my working example of the old select 2 version (v3.5) in jsfiddle. I would like to try and emulate this with the latest version.
Working in Select2 v3.5
Broken in Select2 v4.0.3
And here is the basic code I pieced together.
$('#shipping_state').select2('val', $('#billing_state').select2("val").toString());
Any suggestions welcome. Thank you.
答案 0 :(得分:2)
好的......如果有其他人需要的话,弄明白。
以下是如何将值绑定并复制到其他字段。
$("#shipping_state").val($("#billing_state").val()).trigger("change");
工作示例: