Adding single select support and testing
This commit is contained in:
parent
581af39288
commit
e60ab22a85
8
src/js/select2/selection/single.js
vendored
8
src/js/select2/selection/single.js
vendored
@ -63,11 +63,11 @@ define([
|
||||
this.$selection.find('.select2-selection__rendered').empty();
|
||||
};
|
||||
|
||||
SingleSelection.prototype.display = function (data) {
|
||||
SingleSelection.prototype.display = function (data, container) {
|
||||
var template = this.options.get('templateSelection');
|
||||
var escapeMarkup = this.options.get('escapeMarkup');
|
||||
|
||||
return escapeMarkup(template(data));
|
||||
return escapeMarkup(template(data, container));
|
||||
};
|
||||
|
||||
SingleSelection.prototype.selectionContainer = function () {
|
||||
@ -82,9 +82,9 @@ define([
|
||||
|
||||
var selection = data[0];
|
||||
|
||||
var formatted = this.display(selection);
|
||||
|
||||
var $rendered = this.$selection.find('.select2-selection__rendered');
|
||||
var formatted = this.display(selection, $rendered);
|
||||
|
||||
$rendered.empty().append(formatted);
|
||||
$rendered.prop('title', selection.title || selection.text);
|
||||
};
|
||||
|
@ -34,7 +34,7 @@ test('display uses templateSelection', function (assert) {
|
||||
});
|
||||
|
||||
test('templateSelection can addClass', function (assert) {
|
||||
var called = false, found = false;
|
||||
var called = false;
|
||||
|
||||
var templateOptions = new Options({
|
||||
templateSelection: function (data, container) {
|
||||
|
@ -33,6 +33,35 @@ test('display uses templateSelection', function (assert) {
|
||||
assert.equal(out, 'test');
|
||||
});
|
||||
|
||||
test('templateSelection can addClass', function (assert) {
|
||||
var called = false;
|
||||
|
||||
var templateOptions = new Options({
|
||||
templateSelection: function (data, container) {
|
||||
called = true;
|
||||
container.addClass('testclass');
|
||||
return data.text;
|
||||
}
|
||||
});
|
||||
|
||||
var selection = new SingleSelection(
|
||||
$('#qunit-fixture .single'),
|
||||
templateOptions
|
||||
);
|
||||
|
||||
var $container = selection.selectionContainer();
|
||||
|
||||
var out = selection.display({
|
||||
text: 'test'
|
||||
}, $container);
|
||||
|
||||
assert.ok(called);
|
||||
|
||||
assert.equal(out, 'test');
|
||||
|
||||
assert.ok($container.hasClass('testclass'));
|
||||
});
|
||||
|
||||
test('empty update clears the selection', function (assert) {
|
||||
var selection = new SingleSelection(
|
||||
$('#qunit-fixture .single'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user