I use the functionality of the multiselect to add or remove items, but I need a confirmation before an item will be deleted.
So I use the DataBound-Event to save the current values an everytime the Change-Event is triggered I compare the current values against the previous:
function onChange() {
var previous = this._savedValues;
var current = this.value();
if (current.length < previous.length) {
var diff = $(previous).not(current).get(0);
if (diff != null) {
var memberName = diff.substring(diff.indexOf('CN=') + 3, diff.indexOf(','));
var string = 'Delete' + memberName + '?';
if (confirm(string.replace('{0}', memberName))) {
console.log("confirmed"); // nothing more happens here
}
else {
//reset;
this.value(previous);
}
}
}
saveCurrent(this);
}
function saveCurrent(multi) {
multi._savedValues = multi.value().slice(0);
}
function onDataBound() {
saveCurrent(this);
}
The problem is: This doesn't really work properly. If I add and remove some items, the multiselect deletes more items than I want to remove.