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

Finished off tests for tags

This also adds back the ability for tags to return `null` in order
for no tag to be added to the results.
This commit is contained in:
Kevin Brown 2014-11-26 19:52:10 -05:00
parent 76e4ea8340
commit 56d5778590
8 changed files with 87 additions and 22 deletions

View File

@ -2492,12 +2492,14 @@ define('select2/data/tags',[
var tag = self.createTag(params);
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
if (tag != null) {
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
self.$element.append($option);
self.$element.append($option);
self.insertTag(data, tag);
self.insertTag(data, tag);
}
callback(data);
}

View File

@ -2492,12 +2492,14 @@ define('select2/data/tags',[
var tag = self.createTag(params);
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
if (tag != null) {
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
self.$element.append($option);
self.$element.append($option);
self.insertTag(data, tag);
self.insertTag(data, tag);
}
callback(data);
}

View File

@ -12027,12 +12027,14 @@ define('select2/data/tags',[
var tag = self.createTag(params);
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
if (tag != null) {
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
self.$element.append($option);
self.$element.append($option);
self.insertTag(data, tag);
self.insertTag(data, tag);
}
callback(data);
}

File diff suppressed because one or more lines are too long

10
dist/js/select2.js vendored
View File

@ -2920,12 +2920,14 @@ define('select2/data/tags',[
var tag = self.createTag(params);
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
if (tag != null) {
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
self.$element.append($option);
self.$element.append($option);
self.insertTag(data, tag);
self.insertTag(data, tag);
}
callback(data);
}

File diff suppressed because one or more lines are too long

View File

@ -55,12 +55,14 @@ define([
var tag = self.createTag(params);
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
if (tag != null) {
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
self.$element.append($option);
self.$element.append($option);
self.insertTag(data, tag);
self.insertTag(data, tag);
}
callback(data);
}

View File

@ -130,3 +130,58 @@ test('old tags are removed automatically', function (assert) {
assert.equal($tag.text(), 'second');
});
});
test('insertTag controls the tag location', function (assert) {
var data = new SelectTags($('#qunit-fixture .single'), options);
data.insertTag = function (data, tag) {
data.push(tag);
};
data.query({
term: 'o'
}, function (data) {
assert.equal(data.length, 2);
var item = data[1];
assert.equal(item.id, 'o');
assert.equal(item.text, 'o');
});
});
test('createTag controls the tag object', function (assert) {
var data = new SelectTags($('#qunit-fixture .single'), options);
data.createTag = function (params) {
return {
id: 0,
text: params.term
};
};
data.query({
term: 'test'
}, function (data) {
assert.equal(data.length, 1);
var item = data[0];
assert.equal(item.id, 0);
assert.equal(item.text, 'test');
});
});
test('createTag returns null for no tag', function (assert) {
var data = new SelectTags($('#qunit-fixture .single'), options);
data.createTag = function (params) {
return null;
};
data.query({
term: 'o'
}, function (data) {
assert.equal(data.length, 1);
});
});