Skip to content

Commit ea2e772

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
SelectBox: Should render only the latest passed value when async template is used (T1262587) (DevExpress#29122)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent d219738 commit ea2e772

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,8 @@ const DropDownEditor = TextBox.inherit({
353353
container: getPublicElement($templateWrapper),
354354
onRendered: () => {
355355
if (this._activeRenderContext !== currentRenderContext) {
356-
return;
357-
}
358-
359-
const isRenderedInRoot = !!this.$element().find($templateWrapper).length;
356+
$templateWrapper.empty();
360357

361-
if (!isRenderedInRoot) {
362358
return;
363359
}
364360

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const OVERLAY_CONTENT_CLASS = 'dx-overlay-content';
7777
const CLEAR_BUTTON_AREA = 'dx-clear-button-area';
7878
const SCROLLVIEW_CONTENT_CLASS = 'dx-scrollview-content';
7979
const LIST_ITEMS_CLASS = 'dx-list-items';
80+
const DROP_DOWN_EDITOR_FIELD_TEMPLATE_WRAPPER = 'dx-dropdowneditor-field-template-wrapper';
8081

8182
const KEY_DOWN = 'ArrowDown';
8283
const KEY_ENTER = 'Enter';
@@ -4383,6 +4384,49 @@ QUnit.module('Async tests', {}, () => {
43834384
this.clock.restore();
43844385
}
43854386
});
4387+
4388+
QUnit.test('component with async fieldTemplate render only one value on re-render (T1262587)', function(assert) {
4389+
const clock = sinon.useFakeTimers();
4390+
4391+
const $selectBox = $('#selectBox').dxSelectBox({
4392+
items: [1, 2, 3],
4393+
fieldTemplate: 'custom',
4394+
templatesRenderAsynchronously: true,
4395+
integrationOptions: {
4396+
templates: {
4397+
custom: {
4398+
render: function(args) {
4399+
const result = $('<div>');
4400+
setTimeout(() => {
4401+
result.dxTextBox({
4402+
value: args.model ? args.model.text : '',
4403+
});
4404+
4405+
result.appendTo(args.container);
4406+
args.onRendered();
4407+
}, TIME_TO_WAIT);
4408+
4409+
return result;
4410+
}
4411+
}
4412+
}
4413+
},
4414+
});
4415+
4416+
const instance = $selectBox.dxSelectBox('instance');
4417+
4418+
instance.option({ value: 1 });
4419+
instance.option({ value: null });
4420+
4421+
clock.tick(TIME_TO_WAIT);
4422+
4423+
const $wrapper = $selectBox.find(toSelector(DROP_DOWN_EDITOR_FIELD_TEMPLATE_WRAPPER));
4424+
const $input = $selectBox.find(toSelector(TEXTEDITOR_INPUT_CLASS));
4425+
assert.strictEqual($wrapper.children().length, 1, 'only 1 element is rendered');
4426+
assert.strictEqual($input.val(), '', 'last value is applied');
4427+
4428+
clock.restore();
4429+
});
43864430
});
43874431

43884432
QUnit.module('regressions', moduleSetup, () => {

0 commit comments

Comments
 (0)