Merge pull request #3565 from rockshandy/issue-3564
use merged data instead of existingData for ArrayAdapter
This commit is contained in:
commit
47895b1e45
2
src/js/select2/data/array.js
vendored
2
src/js/select2/data/array.js
vendored
@ -54,7 +54,7 @@ define([
|
||||
var existingData = this.item($existingOption);
|
||||
var newData = $.extend(true, {}, existingData, item);
|
||||
|
||||
var $newOption = this.option(existingData);
|
||||
var $newOption = this.option(newData);
|
||||
|
||||
$existingOption.replaceWith($newOption);
|
||||
|
||||
|
@ -21,6 +21,21 @@ var arrayOptions = new Options({
|
||||
]
|
||||
});
|
||||
|
||||
var extraOptions = new Options ({
|
||||
data: [
|
||||
{
|
||||
id: 'default',
|
||||
text: 'Default',
|
||||
extra: true
|
||||
},
|
||||
{
|
||||
id: 'One',
|
||||
text: 'One',
|
||||
extra: true
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
var nestedOptions = new Options({
|
||||
data: [
|
||||
{
|
||||
@ -206,6 +221,36 @@ test('option tags are automatically generated', function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
test('option tags can receive new data', function(assert) {
|
||||
var $select = $('#qunit-fixture .single');
|
||||
|
||||
var data = new ArrayData($select, extraOptions);
|
||||
|
||||
assert.equal(
|
||||
$select.find('option').length,
|
||||
2,
|
||||
'Only one more <option> element should be created'
|
||||
);
|
||||
|
||||
data.select({
|
||||
id: 'default'
|
||||
});
|
||||
|
||||
assert.ok(
|
||||
$select.find(':selected').data('data').extra,
|
||||
'<option> default should have new data'
|
||||
);
|
||||
|
||||
data.select({
|
||||
id: 'One'
|
||||
});
|
||||
|
||||
assert.ok(
|
||||
$select.find(':selected').data('data').extra,
|
||||
'<option> One should have new data'
|
||||
);
|
||||
});
|
||||
|
||||
test('optgroup tags can also be generated', function (assert) {
|
||||
var $select = $('#qunit-fixture .single-empty');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user