Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perform deep merge for Defaults.set() #4364

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/select2/defaults.js
Expand Up @@ -387,7 +387,7 @@ define([

var convertedData = Utils._convertData(data);

$.extend(this.defaults, convertedData);
$.extend(true, this.defaults, convertedData);
};

var defaults = new Defaults();
Expand Down
20 changes: 19 additions & 1 deletion tests/options/ajax-tests.js
Expand Up @@ -29,4 +29,22 @@ test('options are merged recursively with default options', function (assert) {
);

defaults.reset();
});
});

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be ajax--data-type, to match the HTML attribute.


assert.equal(
defaults.defaults.ajax.delay,
ajaxDelay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a comma here, and that is failing the build.

'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();
});