Skip to content

Commit 6be1a97

Browse files
authored
TreeView: skip updating checkbox if not existed (T1307114) (#31085)
1 parent 10f30ea commit 6be1a97

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/devextreme/js/__internal/ui/tree_view/m_tree_view.base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ class TreeViewBase extends HierarchicalCollectionWidget<TreeViewBaseProperties>
14871487
this.setAria('selected', nodeSelection, $node);
14881488

14891489
if (this._showCheckboxes()) {
1490-
this._getCheckBoxInstance($node).option('value', nodeSelection);
1490+
this._getCheckBoxInstance($node)?.option('value', nodeSelection);
14911491
}
14921492
});
14931493

packages/devextreme/testing/tests/DevExpress.ui.widgets/treeView.async.tests.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,50 @@ QUnit.module('Async render', () => {
119119
}, asyncTemplateRenderTimeout);
120120
});
121121
});
122+
123+
QUnit.test('selectItem triggered in onContentReady works properly for asynchronous templates (T1307114)', function(assert) {
124+
const done = assert.async();
125+
126+
let instance = null;
127+
128+
try {
129+
instance = new TreeView($('#treeView'), {
130+
dataSource: [{ text: 'item 1', id: 1 }, { text: 'item 2', id: 2 }],
131+
selectionMode: 'multiple',
132+
showCheckBoxesMode: 'selectAll',
133+
itemTemplate: 'custom',
134+
onContentReady: (e) => {
135+
e.component.selectItem(1);
136+
},
137+
templatesRenderAsynchronously: true,
138+
integrationOptions: {
139+
templates: {
140+
custom: {
141+
render: function({ container, onRendered, model }) {
142+
setTimeout(() => {
143+
$('<div>').text(model.text).appendTo(container);
144+
onRendered();
145+
});
146+
}
147+
}
148+
}
149+
},
150+
});
151+
assert.ok(true, 'No error should be thrown');
152+
} catch(e) {
153+
assert.ok(false, `Error should not be thrown: ${e}`);
154+
}
155+
156+
setTimeout(() => {
157+
const element = instance.itemsContainer();
158+
const $firstCheckbox = $(element).find(`.${CHECKBOX_CLASS}`);
159+
const firstCheckboxInstance = $firstCheckbox.dxCheckBox('instance');
160+
161+
assert.strictEqual($firstCheckbox.eq(0).hasClass(CHECKBOX_CHECKED_CLASS), true, 'checkbox has selected class');
162+
assert.strictEqual(firstCheckboxInstance.option('value'), true, 'checkbox value is correct');
163+
assert.strictEqual(instance.getSelectedNodeKeys()[0], 1, 'item is selected');
164+
165+
done();
166+
}, asyncTemplateRenderTimeout);
167+
});
122168
});

0 commit comments

Comments
 (0)