Skip to content

Commit

Permalink
DropDownButton: Use isObject instead of isPlainObject to support cust…
Browse files Browse the repository at this point in the history
…om constructors in datasource (T1233565) (DevExpress#27590)

Signed-off-by: Anton Kuznetsov <[email protected]>
Co-authored-by: Anton Kuznetsov <[email protected]>
Co-authored-by: Alexander Kozlovskiy <[email protected]>
# Conflicts:
#	packages/devextreme/js/__internal/ui/m_drop_down_button.ts
  • Loading branch information
nikkithelegendarypokemonster committed Jun 14, 2024
1 parent 59a1e37 commit 9cb7672
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions js/ui/drop_down_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DataSource } from '../data/data_source/data_source';
import ArrayStore from '../data/array_store';
import { Deferred } from '../core/utils/deferred';
import { extend } from '../core/utils/extend';
import { isPlainObject, isDefined } from '../core/utils/type';
import { isObject, isPlainObject, isDefined } from '../core/utils/type';
import { ensureDefined, noop } from '../core/utils/common';
import Guid from '../core/guid';
import { getElementWidth, getSizeValue } from './drop_down_editor/utils';
Expand Down Expand Up @@ -545,9 +545,9 @@ const DropDownButton = Widget.inherit({
},

_getDisplayValue(item) {
const isPrimitiveItem = !isPlainObject(item);
const isPrimitiveItem = !isObject(item);
const displayValue = isPrimitiveItem ? item : this._displayGetter(item);
return !isPlainObject(displayValue) ? String(ensureDefined(displayValue, '')) : '';
return !isObject(displayValue) ? String(ensureDefined(displayValue, '')) : '';
},

_updateActionButton(selectedItem) {
Expand Down
27 changes: 27 additions & 0 deletions testing/tests/DevExpress.ui.widgets/dropDownButton.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,33 @@ QUnit.module('deferred datasource', {
assert.strictEqual(this.dropDownButton.option('selectedItem'), null, 'init byKey result is ignored');
});
});

QUnit.test('should display correct text for non-plain objects(T1233565)', function(assert) {
class Alignment {
constructor(id, name, icon) {
this.id = id;
this.name = name;
this.icon = icon;
}
}
const alignments = [
new Alignment(1, 'Left', 'alignleft'),
new Alignment(4, 'Right', 'alignright'),
new Alignment(2, 'Center', 'aligncenter'),
new Alignment(3, 'Justify', 'alignjustify'),
];
const instance = new DropDownButton($('#dropDownButton'), {
displayExpr: 'name',
keyExpr: 'id',
selectedItemKey: 1,
useSelectMode: true,
dataSource: alignments,
});

const textValue = instance.option('text');

assert.strictEqual(textValue, 'Left', 'the selected item text is properly shown');
});
});

QUnit.module('events', {}, () => {
Expand Down

0 comments on commit 9cb7672

Please sign in to comment.