1
0
mirror of synced 2024-11-22 21:16:10 +03:00

Add support for initializing tags

This adds backwards compatibility for the old tags.
This commit is contained in:
Kevin Brown 2014-11-07 20:31:27 -05:00
parent d306fcf82c
commit 10536370de
9 changed files with 93 additions and 3 deletions

View File

@ -1168,6 +1168,13 @@ define('select2/data/select',[
};
SelectAdapter.prototype._normalizeItem = function (item) {
if (item.text == null) {
item = {
id: item,
text: item
};
}
var defaults = {
selected: false,
disabled: false
@ -1334,6 +1341,17 @@ define('select2/data/tags',[
var tags = options.get('tags');
decorated.call(this, $element, options);
if ($.isArray(tags)) {
for (var t = 0; t < tags.length; t++) {
var tag = tags[t];
var item = this._normalizeItem(tag);
var $option = this.option(item);
this.$element.append($option);
}
}
}
Tags.prototype.query = function (decorated, params, callback) {

View File

@ -1168,6 +1168,13 @@ define('select2/data/select',[
};
SelectAdapter.prototype._normalizeItem = function (item) {
if (item.text == null) {
item = {
id: item,
text: item
};
}
var defaults = {
selected: false,
disabled: false
@ -1334,6 +1341,17 @@ define('select2/data/tags',[
var tags = options.get('tags');
decorated.call(this, $element, options);
if ($.isArray(tags)) {
for (var t = 0; t < tags.length; t++) {
var tag = tags[t];
var item = this._normalizeItem(tag);
var $option = this.option(item);
this.$element.append($option);
}
}
}
Tags.prototype.query = function (decorated, params, callback) {

View File

@ -10703,6 +10703,13 @@ define('select2/data/select',[
};
SelectAdapter.prototype._normalizeItem = function (item) {
if (item.text == null) {
item = {
id: item,
text: item
};
}
var defaults = {
selected: false,
disabled: false
@ -10869,6 +10876,17 @@ define('select2/data/tags',[
var tags = options.get('tags');
decorated.call(this, $element, options);
if ($.isArray(tags)) {
for (var t = 0; t < tags.length; t++) {
var tag = tags[t];
var item = this._normalizeItem(tag);
var $option = this.option(item);
this.$element.append($option);
}
}
}
Tags.prototype.query = function (decorated, params, callback) {

File diff suppressed because one or more lines are too long

18
dist/js/select2.js vendored
View File

@ -1596,6 +1596,13 @@ define('select2/data/select',[
};
SelectAdapter.prototype._normalizeItem = function (item) {
if (item.text == null) {
item = {
id: item,
text: item
};
}
var defaults = {
selected: false,
disabled: false
@ -1762,6 +1769,17 @@ define('select2/data/tags',[
var tags = options.get('tags');
decorated.call(this, $element, options);
if ($.isArray(tags)) {
for (var t = 0; t < tags.length; t++) {
var tag = tags[t];
var item = this._normalizeItem(tag);
var $option = this.option(item);
this.$element.append($option);
}
}
}
Tags.prototype.query = function (decorated, params, callback) {

File diff suppressed because one or more lines are too long

View File

@ -554,7 +554,7 @@ $.fn.select2.amd.require(
$(".js-example-programmatic").select2();
$tags.select2({
tags: true
tags: ['red', 'blue', 'green']
});
function matchStart (term, text) {

View File

@ -189,6 +189,13 @@ define([
};
SelectAdapter.prototype._normalizeItem = function (item) {
if (item.text == null) {
item = {
id: item,
text: item
};
}
var defaults = {
selected: false,
disabled: false

View File

@ -5,6 +5,17 @@ define([
var tags = options.get('tags');
decorated.call(this, $element, options);
if ($.isArray(tags)) {
for (var t = 0; t < tags.length; t++) {
var tag = tags[t];
var item = this._normalizeItem(tag);
var $option = this.option(item);
this.$element.append($option);
}
}
}
Tags.prototype.query = function (decorated, params, callback) {