Skip to content

Commit 2d77442

Browse files
authored
DropDownList: Displayed text should be correct when items have nested items field and group is disabled (T1292151)
1 parent bab2d87 commit 2d77442

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

packages/devextreme/js/__internal/ui/drop_down_editor/m_drop_down_list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,12 @@ class DropDownList<
381381

382382
_getPlainItems(items?) {
383383
let plainItems: any = [];
384+
const grouped = this._getGroupedOption();
384385

385386
items = items || this.option('items') || this._dataSource.items() || [];
386387

387388
for (let i = 0; i < items.length; i++) {
388-
if (items[i]?.items) {
389+
if (grouped && items[i]?.items) {
389390
plainItems = plainItems.concat(items[i].items);
390391
} else {
391392
plainItems.push(items[i]);

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownList.tests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,21 @@ QUnit.module('items & dataSource', moduleConfig, () => {
991991
assert.strictEqual(this.dropDownList.option('selectedItem'), null, 'byKey result is ignored');
992992
});
993993
});
994+
995+
QUnit.test('_getPlainItems should return correct items when they have nested items field and grouping is disabled (T1292151)', function(assert) {
996+
const nestedItems = [{ id: 1, text: 'unexpected text' }];
997+
const items = [{ id: 1, text: 'item 1', items: nestedItems }];
998+
999+
const dropDownList = $('#dropDownList').dxDropDownList({
1000+
items,
1001+
displayExpr: 'text',
1002+
valueExpr: 'id',
1003+
}).dxDropDownList('instance');
1004+
1005+
const plainItems = dropDownList._getPlainItems();
1006+
1007+
assert.deepEqual(plainItems, items, 'items are correct');
1008+
});
9941009
});
9951010

9961011
QUnit.module('selectedItem', moduleConfig, () => {

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/lookup.tests.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ QUnit.testStart(function() {
6464
$('#widthRootStyle').css('width', '300px');
6565
});
6666

67-
const OVERLAY_CLASS = 'dx-overlay';
6867
const OVERLAY_SHADER_CLASS = 'dx-overlay-shader';
6968
const OVERLAY_WRAPPER_CLASS = 'dx-overlay-wrapper';
7069
const OVERLAY_CONTENT_CLASS = 'dx-overlay-content';
@@ -2109,6 +2108,22 @@ QUnit.module('options', {
21092108

21102109
assert.strictEqual($field.attr('custom'), undefined, 'custom attribute is set correctly');
21112110
});
2111+
2112+
QUnit.test('Displayed text should be correct when items have nested items field and grouping is disabled (T1292151)', function(assert) {
2113+
const $lookup = $('#lookup').dxLookup({
2114+
items: [
2115+
{ id: 1, text: 'item 1', items: [{ id: 1, text: 'unexpected text' }] },
2116+
],
2117+
value: 1,
2118+
displayExpr: 'text',
2119+
valueExpr: 'id',
2120+
});
2121+
2122+
const $input = $lookup.find(`.${LOOKUP_FIELD_CLASS}`);
2123+
const displayedText = $input.text();
2124+
2125+
assert.strictEqual(displayedText, 'item 1', 'input value is correct');
2126+
});
21122127
});
21132128

21142129
QUnit.module('popup options', {

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/selectBox.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,22 @@ QUnit.module('widget options', moduleSetup, () => {
15731573
assert.ok(false, 'error is trown');
15741574
}
15751575
});
1576+
1577+
QUnit.test('Displayed text should be correct when items have nested items field and grouping is disabled (T1292151)', function(assert) {
1578+
const $selectBox = $('#selectBox').dxSelectBox({
1579+
items: [
1580+
{ id: 1, text: 'item 1', items: [{ id: 1, text: 'unexpected text' }] },
1581+
],
1582+
value: 1,
1583+
displayExpr: 'text',
1584+
valueExpr: 'id',
1585+
});
1586+
1587+
const $input = $selectBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);
1588+
const displayedText = $input.val();
1589+
1590+
assert.strictEqual(displayedText, 'item 1', 'input value is correct');
1591+
});
15761592
});
15771593

15781594
QUnit.module('clearButton', moduleSetup, () => {

0 commit comments

Comments
 (0)