Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelectBox: should not throw an error if its detached template is re-mounted by a framework (T1178295) #25572

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions js/ui/drop_down_editor/ui.drop_down_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ const DropDownEditor = TextBox.inherit({
},

_renderTemplatedField: function(fieldTemplate, data) {
this._fieldRenderQueueLength = (this._fieldRenderQueueLength ?? 0) + 1;

const isFocused = focused(this._input());
const $container = this._$container;

Expand All @@ -354,8 +352,9 @@ const DropDownEditor = TextBox.inherit({
model: data,
container: getPublicElement($templateWrapper),
onRendered: () => {
this._fieldRenderQueueLength--;
if(this._fieldRenderQueueLength !== 0) {
const isRenderedInRoot = !!this.$element().find($templateWrapper).length;

if(!isRenderedInRoot) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isRenderer } from 'core/utils/type';
import caretWorkaround from './textEditorParts/caretWorkaround.js';
import resizeCallbacks from 'core/utils/resize_callbacks';
import dxButton from 'ui/button';
import domAdapter from 'core/dom_adapter';

import 'generic_light.css!';
QUnit.testStart(function() {
Expand Down Expand Up @@ -923,6 +924,42 @@ QUnit.module('Templates', () => {
}
});

QUnit.test('should not raise error if onRendered is received for a removed template (T1178295, T1059261)', function(assert) {
const clock = sinon.useFakeTimers();

const dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({
fieldTemplate: 'field',
templatesRenderAsynchronously: true,
integrationOptions: {
templates: {
field: {
render: function({ container, onRendered }) {
const $input = $('<div>').appendTo(container);

setTimeout(() => {
$input.dxTextBox();
onRendered();
domAdapter.removeElement(container);
domAdapter.removeElement($input);
dropDownEditor.repaint();
onRendered();
}, 100);
}
}
}
},
}).dxDropDownEditor('instance');

try {
clock.tick(110);
} catch(e) {
assert.ok(false, `error is raised: ${e.message}`);
} finally {
clock.restore();
assert.ok(true);
}
});

QUnit.test('onValueChanged should be fired for each change by keyboard when fieldTemplate is used', function(assert) {
const valueChangedSpy = sinon.spy();

Expand Down