I use to set the default value on load for a select (using Select2) with a code like this:
$('#soff_gar').select2({placeholder: "Scegli", initSelection: true }).select2("val","<?php echo $garante; ?>");
Upgrading to version 4.0 on console I read: "Select2: The select2("val")
method has been deprecated and will be removed in later Select2 versions. Use $element.val() instead." So I tried to change my code to
$('#soff_gar').select2({placeholder: "Scegli", initSelection: true }).val("<?php echo $garante; ?>");
or
$('#soff_gar').select2({placeholder: "Scegli"}).val("<?php echo $garante; ?>");
but none of them works. What am I doing wrong? Any hint?