diff --git a/src/js/select2/defaults.js b/src/js/select2/defaults.js index ad4d224f..836a3818 100644 --- a/src/js/select2/defaults.js +++ b/src/js/select2/defaults.js @@ -387,7 +387,7 @@ define([ var convertedData = Utils._convertData(data); - $.extend(this.defaults, convertedData); + $.extend(true, this.defaults, convertedData); }; var defaults = new Defaults(); diff --git a/tests/options/ajax-tests.js b/tests/options/ajax-tests.js index 7d8537ae..e25b656e 100644 --- a/tests/options/ajax-tests.js +++ b/tests/options/ajax-tests.js @@ -29,4 +29,22 @@ test('options are merged recursively with default options', function (assert) { ); defaults.reset(); -}); \ No newline at end of file +}); + +test('more than one default option can be changed via set()', function(assert) { + var defaults = require('select2/defaults'); + var ajaxDelay = 123; + var dataDataType = 'xml' + defaults.set('ajax--delay', ajaxDelay); + defaults.set('ajax--dataType', dataDataType); + + assert.equal( + defaults.defaults.ajax.delay, + ajaxDelay + 'Both ajax.delay and ajax.dataType present in defaults'); + assert.equal( + defaults.defaults.ajax.dataType, + dataDataType, + 'Both ajax.delay and ajax.dataType present in defaults'); + defaults.reset(); +});