You are using change:select
but that is not a select2 event. The closest event to that is change.select2
but that is not what you want. The event you want is select2:select
, which occurs whenever a result is selected.
Given your existing code, you’ve already set isTag
to true
so the rest of your code works as you expect:
}).on("select2:select", function(e) {
console.log('select');
var data = e.params.data;
var requestForm = document.querySelector('form');
if (data.isTag) {
console.log('local tag selected', data);
requestForm.style.display = 'block';
} else {
requestForm.style.display = 'none';
}
});
CLICK HERE to find out more related problems solutions.