According to Select2 docs, an event must have 3 properties: the event object contains the following custom properties:
- val: current selection (taking into account the result of the change) - id or array of identifiers
- added: the added element, if any, is the full object of the element, not just id
- deleted: the deleted element, if any, is the full object of the element, not just id
There is even an example:
$("#e11").select2({ placeholder: "Select value ...", allowClear: true, data: [{id: 0, text: 'story'},{id: 1, text: 'bug'},{id: 2, text: 'task'}] }); $("#e11_2").select2({ placeholder: "Select value ...", multiple: true, data: [{id: 0, text: 'story'},{id: 1, text: 'bug'},{id: 2, text: 'task'}] }); $("#e11").on("change", function(e) { console.log(JSON.stringify({val:e.val, added:e.added, removed:e.removed})); }).on("open", function() { console.log("open"); }); $("#e11_2").on("change", function(e) { console.log(JSON.stringify({val:e.val, added:e.added, removed:e.removed})); }).on("open", function() { console.log("open"); });
But I noticed that the added and removed properties are only present when multiple: true enabled. I do not know if this is by design or this is a mistake. I am going to report this anyway, because having the selected item available for change is definitely necessary.
Primoz rome
source share