Skip to content

Commit

Permalink
Fix text shown in select2 option if value attribute was specified
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohal committed Jul 15, 2016
1 parent 8a68212 commit 662e32e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/js/select2-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
attribs = attribs + ' width="' + imageWidth + '"';
}

return '<img ' + attribs + '>&nbsp;' + option.id;
return '<img ' + attribs + '>&nbsp;' + option.text;
}

return option.id;
return option.text;
};

if (confValue) {
Expand Down
10 changes: 8 additions & 2 deletions src/js/tests/unit/select2-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ $(function () {
return value.formatResult === value.formatSelection;
}));

QUnit.ok(jQuery.fn.select2 .calledWithMatch(function (value) {
var testOpt = { element: $('option'), text: 'optionText' };

return value.formatResult(testOpt) === 'optionText';
}));

QUnit.ok(jQuery.fn.select2 .calledWithMatch(function (value) {
var testOpt = { element: $optEl };
var output = '<img src="imageSource" alt="optionText">&nbsp;optionId';
var output = '<img src="imageSource" alt="optionText">&nbsp;optionText';

$.extend(testOpt, option);

Expand All @@ -78,7 +84,7 @@ $(function () {
var testOpt = { element: $optEl };
var output = '<img ' +
'src="imageSource" alt="optionText" srcset="imageSrcset" height="10" width="10"' +
'>&nbsp;optionId';
'>&nbsp;optionText';

$optEl.attr('data-image-srcset', 'imageSrcset');
$optEl.attr('data-image-width', '10');
Expand Down
2 changes: 2 additions & 0 deletions src/less/components/javascript/select2-loader.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ Markup:
<select class="form-control" data-onload-select2='{"minimumResultsForSearch": "Infinity"}'>
<option
selected
value="flag-czech"
data-image-src="//satyr.io/32x16?flag=cze"
data-image-srcset="//satyr.io/32x16?flag=cze, //satyr.io/64x32?flag=cze 2x"
data-image-width="32"
data-image-height="16"
>Czech</option>
<option
value="flag-canada"
data-image-src="//satyr.io/32x16?flag=can"
data-image-srcset="//satyr.io/32x16?flag=can, //satyr.io/64x32?flag=can 2x"
data-image-width="32"
Expand Down

0 comments on commit 662e32e

Please sign in to comment.