Hi to all, I'm a beginner with select2!
I need to hide an option if MY_COND is true. (And show again when MY_COND is false)
I ended to use a listener to prevent selection this way:
$('#x_my_select').on('select2:select', function (e) {
if ($(e.target).val() == "3" && MY_COND) { //3 IS THE VAL OF THE OPTION TO HIDE
$(e.target).val(null).trigger("change") //RESET SELECTION
ew.alert("OPTION NON ALLOWED!"); //NOT ALLOWED MESSAGE
}
});
It works but I think that hide the option will be better, any suggestions are welcome!!
Thanks!