Skip to content

Commit e3db766

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

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
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
@@ -323,11 +323,12 @@ const DropDownList = DropDownEditor.inherit({
323323

324324
_getPlainItems(items) {
325325
let plainItems: any = [];
326+
const grouped = this._getGroupedOption();
326327

327328
items = items || this.option('items') || this._dataSource.items() || [];
328329

329330
for (let i = 0; i < items.length; i++) {
330-
if (items[i] && items[i].items) {
331+
if (grouped && items[i]?.items) {
331332
plainItems = plainItems.concat(items[i].items);
332333
} else {
333334
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,22 @@ QUnit.module('options', {
21042104

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

21092125
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)