Skip to content

Commit be0bdeb

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

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
@@ -990,6 +990,21 @@ QUnit.module('items & dataSource', moduleConfig, () => {
990990
assert.strictEqual(this.dropDownList.option('selectedItem'), null, 'byKey result is ignored');
991991
});
992992
});
993+
994+
QUnit.test('_getPlainItems should return correct items when they have nested items field and grouping is disabled (T1292151)', function(assert) {
995+
const nestedItems = [{ id: 1, text: 'unexpected text' }];
996+
const items = [{ id: 1, text: 'item 1', items: nestedItems }];
997+
998+
const dropDownList = $('#dropDownList').dxDropDownList({
999+
items,
1000+
displayExpr: 'text',
1001+
valueExpr: 'id',
1002+
}).dxDropDownList('instance');
1003+
1004+
const plainItems = dropDownList._getPlainItems();
1005+
1006+
assert.deepEqual(plainItems, items, 'items are correct');
1007+
});
9931008
});
9941009

9951010
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
@@ -65,7 +65,6 @@ QUnit.testStart(function() {
6565
$('#widthRootStyle').css('width', '300px');
6666
});
6767

68-
const OVERLAY_CLASS = 'dx-overlay';
6968
const OVERLAY_SHADER_CLASS = 'dx-overlay-shader';
7069
const OVERLAY_WRAPPER_CLASS = 'dx-overlay-wrapper';
7170
const OVERLAY_CONTENT_CLASS = 'dx-overlay-content';
@@ -2108,6 +2107,22 @@ QUnit.module('options', {
21082107

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

21132128
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
@@ -1572,6 +1572,22 @@ QUnit.module('widget options', moduleSetup, () => {
15721572
assert.ok(false, 'error is trown');
15731573
}
15741574
});
1575+
1576+
QUnit.test('Displayed text should be correct when items have nested items field and grouping is disabled (T1292151)', function(assert) {
1577+
const $selectBox = $('#selectBox').dxSelectBox({
1578+
items: [
1579+
{ id: 1, text: 'item 1', items: [{ id: 1, text: 'unexpected text' }] },
1580+
],
1581+
value: 1,
1582+
displayExpr: 'text',
1583+
valueExpr: 'id',
1584+
});
1585+
1586+
const $input = $selectBox.find(`.${TEXTEDITOR_INPUT_CLASS}`);
1587+
const displayedText = $input.val();
1588+
1589+
assert.strictEqual(displayedText, 'item 1', 'input value is correct');
1590+
});
15751591
});
15761592

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

0 commit comments

Comments
 (0)