Clicking on a selected option triggers an unselect event
This commit is contained in:
parent
94b460f930
commit
d57f8b2203
52
dist/js/select2.amd.full.js
vendored
52
dist/js/select2.amd.full.js
vendored
@ -190,18 +190,41 @@ define('select2/data/select',[
|
|||||||
this.$element.val(val);
|
this.$element.val(val);
|
||||||
this.$element.trigger("change");
|
this.$element.trigger("change");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SelectAdapter.prototype.unselect = function (data) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (!this.$element.prop("multiple")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.current(function (currentData) {
|
||||||
|
var val = [];
|
||||||
|
|
||||||
|
for (var d = 0; d < currentData.length; d++) {
|
||||||
|
id = currentData[d].id;
|
||||||
|
|
||||||
|
if (id !== data.id && val.indexOf(id) === -1) {
|
||||||
|
val.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.$element.val(val);
|
||||||
|
self.$element.trigger("change");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.bind = function (container, $container) {
|
SelectAdapter.prototype.bind = function (container, $container) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
container.on("select", function (params) {
|
container.on("select", function (params) {
|
||||||
var current = self.current(function (data) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
|
|
||||||
self.select(params.data);
|
self.select(params.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
container.on("unselect", function (params) {
|
||||||
|
self.unselect(params.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.query = function (params, callback) {
|
SelectAdapter.prototype.query = function (params, callback) {
|
||||||
@ -323,6 +346,7 @@ define('select2/results',[
|
|||||||
this.on("results:all", function (data) {
|
this.on("results:all", function (data) {
|
||||||
self.clear();
|
self.clear();
|
||||||
self.append(data);
|
self.append(data);
|
||||||
|
|
||||||
self.setClasses();
|
self.setClasses();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -333,7 +357,19 @@ define('select2/results',[
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.$results.on("click", ".option", function (evt) {
|
this.$results.on("click", ".option", function (evt) {
|
||||||
var data = $(this).data("data");
|
var $this = $(this);
|
||||||
|
|
||||||
|
var data = $this.data("data");
|
||||||
|
if ($this.hasClass("selected")) {
|
||||||
|
self.trigger("unselected", {
|
||||||
|
originalEvent: evt,
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
|
||||||
|
self.setClasses();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger("selected", {
|
self.trigger("selected", {
|
||||||
originalEvent: evt,
|
originalEvent: evt,
|
||||||
@ -615,6 +651,12 @@ define('select2/core',[
|
|||||||
$container.removeClass("open");
|
$container.removeClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.results.on("unselected", function (params) {
|
||||||
|
self.trigger("unselect", params);
|
||||||
|
|
||||||
|
$container.removeClass("open");
|
||||||
|
});
|
||||||
|
|
||||||
// Set the initial state
|
// Set the initial state
|
||||||
|
|
||||||
this.data.current(function (initialData) {
|
this.data.current(function (initialData) {
|
||||||
|
52
dist/js/select2.amd.js
vendored
52
dist/js/select2.amd.js
vendored
@ -190,18 +190,41 @@ define('select2/data/select',[
|
|||||||
this.$element.val(val);
|
this.$element.val(val);
|
||||||
this.$element.trigger("change");
|
this.$element.trigger("change");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SelectAdapter.prototype.unselect = function (data) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (!this.$element.prop("multiple")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.current(function (currentData) {
|
||||||
|
var val = [];
|
||||||
|
|
||||||
|
for (var d = 0; d < currentData.length; d++) {
|
||||||
|
id = currentData[d].id;
|
||||||
|
|
||||||
|
if (id !== data.id && val.indexOf(id) === -1) {
|
||||||
|
val.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.$element.val(val);
|
||||||
|
self.$element.trigger("change");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.bind = function (container, $container) {
|
SelectAdapter.prototype.bind = function (container, $container) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
container.on("select", function (params) {
|
container.on("select", function (params) {
|
||||||
var current = self.current(function (data) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
|
|
||||||
self.select(params.data);
|
self.select(params.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
container.on("unselect", function (params) {
|
||||||
|
self.unselect(params.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.query = function (params, callback) {
|
SelectAdapter.prototype.query = function (params, callback) {
|
||||||
@ -323,6 +346,7 @@ define('select2/results',[
|
|||||||
this.on("results:all", function (data) {
|
this.on("results:all", function (data) {
|
||||||
self.clear();
|
self.clear();
|
||||||
self.append(data);
|
self.append(data);
|
||||||
|
|
||||||
self.setClasses();
|
self.setClasses();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -333,7 +357,19 @@ define('select2/results',[
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.$results.on("click", ".option", function (evt) {
|
this.$results.on("click", ".option", function (evt) {
|
||||||
var data = $(this).data("data");
|
var $this = $(this);
|
||||||
|
|
||||||
|
var data = $this.data("data");
|
||||||
|
if ($this.hasClass("selected")) {
|
||||||
|
self.trigger("unselected", {
|
||||||
|
originalEvent: evt,
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
|
||||||
|
self.setClasses();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger("selected", {
|
self.trigger("selected", {
|
||||||
originalEvent: evt,
|
originalEvent: evt,
|
||||||
@ -615,6 +651,12 @@ define('select2/core',[
|
|||||||
$container.removeClass("open");
|
$container.removeClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.results.on("unselected", function (params) {
|
||||||
|
self.trigger("unselect", params);
|
||||||
|
|
||||||
|
$container.removeClass("open");
|
||||||
|
});
|
||||||
|
|
||||||
// Set the initial state
|
// Set the initial state
|
||||||
|
|
||||||
this.data.current(function (initialData) {
|
this.data.current(function (initialData) {
|
||||||
|
52
dist/js/select2.full.js
vendored
52
dist/js/select2.full.js
vendored
@ -9727,18 +9727,41 @@ define('select2/data/select',[
|
|||||||
this.$element.val(val);
|
this.$element.val(val);
|
||||||
this.$element.trigger("change");
|
this.$element.trigger("change");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SelectAdapter.prototype.unselect = function (data) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (!this.$element.prop("multiple")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.current(function (currentData) {
|
||||||
|
var val = [];
|
||||||
|
|
||||||
|
for (var d = 0; d < currentData.length; d++) {
|
||||||
|
id = currentData[d].id;
|
||||||
|
|
||||||
|
if (id !== data.id && val.indexOf(id) === -1) {
|
||||||
|
val.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.$element.val(val);
|
||||||
|
self.$element.trigger("change");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.bind = function (container, $container) {
|
SelectAdapter.prototype.bind = function (container, $container) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
container.on("select", function (params) {
|
container.on("select", function (params) {
|
||||||
var current = self.current(function (data) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
|
|
||||||
self.select(params.data);
|
self.select(params.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
container.on("unselect", function (params) {
|
||||||
|
self.unselect(params.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.query = function (params, callback) {
|
SelectAdapter.prototype.query = function (params, callback) {
|
||||||
@ -9860,6 +9883,7 @@ define('select2/results',[
|
|||||||
this.on("results:all", function (data) {
|
this.on("results:all", function (data) {
|
||||||
self.clear();
|
self.clear();
|
||||||
self.append(data);
|
self.append(data);
|
||||||
|
|
||||||
self.setClasses();
|
self.setClasses();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -9870,7 +9894,19 @@ define('select2/results',[
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.$results.on("click", ".option", function (evt) {
|
this.$results.on("click", ".option", function (evt) {
|
||||||
var data = $(this).data("data");
|
var $this = $(this);
|
||||||
|
|
||||||
|
var data = $this.data("data");
|
||||||
|
if ($this.hasClass("selected")) {
|
||||||
|
self.trigger("unselected", {
|
||||||
|
originalEvent: evt,
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
|
||||||
|
self.setClasses();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger("selected", {
|
self.trigger("selected", {
|
||||||
originalEvent: evt,
|
originalEvent: evt,
|
||||||
@ -10152,6 +10188,12 @@ define('select2/core',[
|
|||||||
$container.removeClass("open");
|
$container.removeClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.results.on("unselected", function (params) {
|
||||||
|
self.trigger("unselect", params);
|
||||||
|
|
||||||
|
$container.removeClass("open");
|
||||||
|
});
|
||||||
|
|
||||||
// Set the initial state
|
// Set the initial state
|
||||||
|
|
||||||
this.data.current(function (initialData) {
|
this.data.current(function (initialData) {
|
||||||
|
52
dist/js/select2.js
vendored
52
dist/js/select2.js
vendored
@ -618,18 +618,41 @@ define('select2/data/select',[
|
|||||||
this.$element.val(val);
|
this.$element.val(val);
|
||||||
this.$element.trigger("change");
|
this.$element.trigger("change");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SelectAdapter.prototype.unselect = function (data) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (!this.$element.prop("multiple")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.current(function (currentData) {
|
||||||
|
var val = [];
|
||||||
|
|
||||||
|
for (var d = 0; d < currentData.length; d++) {
|
||||||
|
id = currentData[d].id;
|
||||||
|
|
||||||
|
if (id !== data.id && val.indexOf(id) === -1) {
|
||||||
|
val.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.$element.val(val);
|
||||||
|
self.$element.trigger("change");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.bind = function (container, $container) {
|
SelectAdapter.prototype.bind = function (container, $container) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
container.on("select", function (params) {
|
container.on("select", function (params) {
|
||||||
var current = self.current(function (data) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
|
|
||||||
self.select(params.data);
|
self.select(params.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
container.on("unselect", function (params) {
|
||||||
|
self.unselect(params.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.query = function (params, callback) {
|
SelectAdapter.prototype.query = function (params, callback) {
|
||||||
@ -751,6 +774,7 @@ define('select2/results',[
|
|||||||
this.on("results:all", function (data) {
|
this.on("results:all", function (data) {
|
||||||
self.clear();
|
self.clear();
|
||||||
self.append(data);
|
self.append(data);
|
||||||
|
|
||||||
self.setClasses();
|
self.setClasses();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -761,7 +785,19 @@ define('select2/results',[
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.$results.on("click", ".option", function (evt) {
|
this.$results.on("click", ".option", function (evt) {
|
||||||
var data = $(this).data("data");
|
var $this = $(this);
|
||||||
|
|
||||||
|
var data = $this.data("data");
|
||||||
|
if ($this.hasClass("selected")) {
|
||||||
|
self.trigger("unselected", {
|
||||||
|
originalEvent: evt,
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
|
||||||
|
self.setClasses();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger("selected", {
|
self.trigger("selected", {
|
||||||
originalEvent: evt,
|
originalEvent: evt,
|
||||||
@ -1043,6 +1079,12 @@ define('select2/core',[
|
|||||||
$container.removeClass("open");
|
$container.removeClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.results.on("unselected", function (params) {
|
||||||
|
self.trigger("unselect", params);
|
||||||
|
|
||||||
|
$container.removeClass("open");
|
||||||
|
});
|
||||||
|
|
||||||
// Set the initial state
|
// Set the initial state
|
||||||
|
|
||||||
this.data.current(function (initialData) {
|
this.data.current(function (initialData) {
|
||||||
|
6
src/js/select2/core.js
vendored
6
src/js/select2/core.js
vendored
@ -71,6 +71,12 @@ define([
|
|||||||
$container.removeClass("open");
|
$container.removeClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.results.on("unselected", function (params) {
|
||||||
|
self.trigger("unselect", params);
|
||||||
|
|
||||||
|
$container.removeClass("open");
|
||||||
|
});
|
||||||
|
|
||||||
// Set the initial state
|
// Set the initial state
|
||||||
|
|
||||||
this.data.current(function (initialData) {
|
this.data.current(function (initialData) {
|
||||||
|
31
src/js/select2/data/select.js
vendored
31
src/js/select2/data/select.js
vendored
@ -52,18 +52,41 @@ define([
|
|||||||
this.$element.val(val);
|
this.$element.val(val);
|
||||||
this.$element.trigger("change");
|
this.$element.trigger("change");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SelectAdapter.prototype.unselect = function (data) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (!this.$element.prop("multiple")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.current(function (currentData) {
|
||||||
|
var val = [];
|
||||||
|
|
||||||
|
for (var d = 0; d < currentData.length; d++) {
|
||||||
|
id = currentData[d].id;
|
||||||
|
|
||||||
|
if (id !== data.id && val.indexOf(id) === -1) {
|
||||||
|
val.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.$element.val(val);
|
||||||
|
self.$element.trigger("change");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.bind = function (container, $container) {
|
SelectAdapter.prototype.bind = function (container, $container) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
container.on("select", function (params) {
|
container.on("select", function (params) {
|
||||||
var current = self.current(function (data) {
|
|
||||||
//
|
|
||||||
});
|
|
||||||
|
|
||||||
self.select(params.data);
|
self.select(params.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
container.on("unselect", function (params) {
|
||||||
|
self.unselect(params.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectAdapter.prototype.query = function (params, callback) {
|
SelectAdapter.prototype.query = function (params, callback) {
|
||||||
|
15
src/js/select2/results.js
vendored
15
src/js/select2/results.js
vendored
@ -76,6 +76,7 @@ define([
|
|||||||
this.on("results:all", function (data) {
|
this.on("results:all", function (data) {
|
||||||
self.clear();
|
self.clear();
|
||||||
self.append(data);
|
self.append(data);
|
||||||
|
|
||||||
self.setClasses();
|
self.setClasses();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -86,7 +87,19 @@ define([
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.$results.on("click", ".option", function (evt) {
|
this.$results.on("click", ".option", function (evt) {
|
||||||
var data = $(this).data("data");
|
var $this = $(this);
|
||||||
|
|
||||||
|
var data = $this.data("data");
|
||||||
|
if ($this.hasClass("selected")) {
|
||||||
|
self.trigger("unselected", {
|
||||||
|
originalEvent: evt,
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
|
||||||
|
self.setClasses();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.trigger("selected", {
|
self.trigger("selected", {
|
||||||
originalEvent: evt,
|
originalEvent: evt,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user