diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d965166..dc2312de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 4.0.5 +### Bug fixes +- User-defined types not normalized properly when passed in as data (#4632) + ### Translations - Czech: Add missing commas and periods (#5052) - Spanish: Update the 'errorLoading' message (#5032) diff --git a/src/js/select2/data/select.js b/src/js/select2/data/select.js index b36b9760..abad2a05 100644 --- a/src/js/select2/data/select.js +++ b/src/js/select2/data/select.js @@ -244,7 +244,7 @@ define([ }; SelectAdapter.prototype._normalizeItem = function (item) { - if(item !== Object(item)){ + if (item !== Object(item)) { item = { id: item, text: item diff --git a/tests/data/array-tests.js b/tests/data/array-tests.js index cbea97c5..08b806ae 100644 --- a/tests/data/array-tests.js +++ b/tests/data/array-tests.js @@ -4,12 +4,12 @@ var ArrayData = require('select2/data/array'); var $ = require('jquery'); var Options = require('select2/options'); -var UserDefinedType = function( id, text ){ - var self=this; +var UserDefinedType = function (id, text) { + var self = this; + + self.id = id; + self.text = text; - self.id=id; - self.text=text; - return self; }; diff --git a/tests/data/select-tests.js b/tests/data/select-tests.js index 30a9b0e1..abb1e484 100644 --- a/tests/data/select-tests.js +++ b/tests/data/select-tests.js @@ -491,12 +491,12 @@ test('select option construction accepts id="" (empty string) value', test('user-defined types are normalized properly', function (assert) { var $select = $('#qunit-fixture .user-defined'), - UserDefinedType = function( id, text ){ - var self=this; + UserDefinedType = function (id, text) { + var self = this; + + self.id = id; + self.text = text; - self.id=id; - self.text=text; - return self; }; @@ -507,14 +507,14 @@ test('user-defined types are normalized properly', function (assert) { text: 'item' }, new UserDefinedType(1, 'aaaaaa') -]; + ]; var data = new SelectData($select, selectOptions); var normalizedItem = data._normalizeItem(testData[0]); var normalizedItem2 = data._normalizeItem(testData[1]); var normalizedItem3 = data._normalizeItem(testData[2]); - + assert.equal( testData[0], normalizedItem.id,