1
0
mirror of synced 2024-11-26 14:56:07 +03:00

allow '0' vals to be set. fixes #646

This commit is contained in:
Igor Vaynberg 2013-01-31 17:10:30 -08:00
parent 32249cc7f0
commit c66a91a9bb

View File

@ -741,6 +741,13 @@ the specific language governing permissions and limitations under the Apache Lic
opts.id = function (e) { return e[idKey]; }; opts.id = function (e) { return e[idKey]; };
} }
if ($.isArray(opts.element.data("select2Tags"))) {
if ("tags" in opts) {
throw "tags specified as both an attribute 'data-select2-tags' and in options of Select2 " + opts.element.attr("id");
}
opts.tags=opts.element.attr("data-select2-tags");
}
if (select) { if (select) {
opts.query = this.bind(function (query) { opts.query = this.bind(function (query) {
var data = { results: [], more: false }, var data = { results: [], more: false },
@ -781,6 +788,7 @@ the specific language governing permissions and limitations under the Apache Lic
opts.formatResultCssClass = function(data) { return data.css; } opts.formatResultCssClass = function(data) { return data.css; }
} else { } else {
if (!("query" in opts)) { if (!("query" in opts)) {
if ("ajax" in opts) { if ("ajax" in opts) {
ajaxUrl = opts.element.data("ajax-url"); ajaxUrl = opts.element.data("ajax-url");
if (ajaxUrl && ajaxUrl.length > 0) { if (ajaxUrl && ajaxUrl.length > 0) {
@ -1789,8 +1797,8 @@ the specific language governing permissions and limitations under the Apache Lic
if (this.opts.initSelection === undefined) { if (this.opts.initSelection === undefined) {
throw new Error("cannot call val() if initSelection() is not defined"); throw new Error("cannot call val() if initSelection() is not defined");
} }
// val is an id. !val is true for [undefined,null,''] // val is an id. !val is true for [undefined,null,'',0] - 0 is legal
if (!val) { if (!val && val !== 0) {
this.clear(); this.clear();
if (triggerChange) { if (triggerChange) {
this.triggerChange(); this.triggerChange();
@ -2326,7 +2334,8 @@ the specific language governing permissions and limitations under the Apache Lic
triggerChange = arguments[1]; triggerChange = arguments[1];
} }
if (!val) { // val is an id. !val is true for [undefined,null,'',0] - 0 is legal
if (!val && val !== 0) {
this.opts.element.val(""); this.opts.element.val("");
this.updateSelection([]); this.updateSelection([]);
this.clearSearch(); this.clearSearch();