Skip to content

Commit 62fedc7

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

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';
@@ -4418,6 +4419,49 @@ QUnit.module('Async tests', {}, () => {
44184419

44194420
clock.restore();
44204421
});
4422+
4423+
QUnit.test('component with async fieldTemplate render only one value on re-render (T1262587)', function(assert) {
4424+
const clock = sinon.useFakeTimers();
4425+
4426+
const $selectBox = $('#selectBox').dxSelectBox({
4427+
items: [1, 2, 3],
4428+
fieldTemplate: 'custom',
4429+
templatesRenderAsynchronously: true,
4430+
integrationOptions: {
4431+
templates: {
4432+
custom: {
4433+
render: function(args) {
4434+
const result = $('<div>');
4435+
setTimeout(() => {
4436+
result.dxTextBox({
4437+
value: args.model ? args.model.text : '',
4438+
});
4439+
4440+
result.appendTo(args.container);
4441+
args.onRendered();
4442+
}, TIME_TO_WAIT);
4443+
4444+
return result;
4445+
}
4446+
}
4447+
}
4448+
},
4449+
});
4450+
4451+
const instance = $selectBox.dxSelectBox('instance');
4452+
4453+
instance.option({ value: 1 });
4454+
instance.option({ value: null });
4455+
4456+
clock.tick(TIME_TO_WAIT);
4457+
4458+
const $wrapper = $selectBox.find(toSelector(DROP_DOWN_EDITOR_FIELD_TEMPLATE_WRAPPER));
4459+
const $input = $selectBox.find(toSelector(TEXTEDITOR_INPUT_CLASS));
4460+
assert.strictEqual($wrapper.children().length, 1, 'only 1 element is rendered');
4461+
assert.strictEqual($input.val(), '', 'last value is applied');
4462+
4463+
clock.restore();
4464+
});
44214465
});
44224466

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

0 commit comments

Comments
 (0)