Skip to content

Commit 8f15e7d

Browse files
fix: popup title bar shows [object Object] when jQuery 4.0 Beta is used (T1280032) (#29913)
1 parent 87dc0b9 commit 8f15e7d

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/devextreme/js/core/utils/dom.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ export const extractTemplateMarkup = (element) => {
8080
};
8181

8282
export const normalizeTemplateElement = (element) => {
83-
let $element = isDefined(element) && (element.nodeType || isRenderer(element))
84-
? $(element)
85-
: $('<div>').html(element).contents();
83+
let $element = $();
84+
85+
if(isDefined(element) && (element.nodeType || isRenderer(element))) {
86+
$element = $(element);
87+
} else if(typeof element !== 'object') {
88+
$element = $('<div>').html(element).contents();
89+
}
8690

8791
if($element.length === 1) {
8892
if($element.is('script')) {

packages/devextreme/testing/tests/DevExpress.core/utils.dom.tests.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
import $ from 'jquery';
22
import domUtils from 'core/utils/dom';
33
import support from 'core/utils/support';
4+
import { EmptyTemplate } from 'core/templates/empty_template';
45
import styleUtils from 'core/utils/style';
56
import devices from 'core/devices';
67
import initMobileViewport from 'mobile/init_mobile_viewport';
78
import keyboardMock from '../../helpers/keyboardMock.js';
89

910
QUnit.module('createMarkup');
1011

12+
QUnit.test('normalizeTemplateElement returns a wrapper if given an element', function(assert) {
13+
const domElement = document.createElement('span');
14+
15+
domElement.innerHTML = 'Some text';
16+
17+
const $result = domUtils.normalizeTemplateElement(domElement);
18+
19+
assert.equal($result.length, 1, 'normalizeTemplateElement works with elements');
20+
assert.equal($result[0].localName, 'span', 'normalizeTemplateElement works with elements');
21+
assert.equal($result.text(), 'Some text', 'normalizeTemplateElement works with elements');
22+
});
23+
24+
QUnit.test('normalizeTemplateElement returns a wrapper if given an HTML string', function(assert) {
25+
const htmlString = '<span>Some text</span>';
26+
27+
const $result = domUtils.normalizeTemplateElement(htmlString);
28+
29+
assert.equal($result.length, 1, 'normalizeTemplateElement works with strings');
30+
assert.equal($result[0].localName, 'span', 'normalizeTemplateElement works with strings');
31+
assert.equal($result.text(), 'Some text', 'normalizeTemplateElement works with strings');
32+
});
33+
34+
QUnit.test('normalizeTemplateElement returns an empty element for other inputs (T1280032) (jQuery 4)', function(assert) {
35+
const template = new EmptyTemplate();
36+
37+
const $result = domUtils.normalizeTemplateElement(template);
38+
39+
assert.equal($result.length, 0, 'normalizeTemplateElement works with TemplateBase objects');
40+
});
41+
1142
QUnit.test('normalizeTemplateElement with script element', function(assert) {
1243
const domElement = document.createElement('script');
1344

@@ -18,7 +49,6 @@ QUnit.test('normalizeTemplateElement with script element', function(assert) {
1849
assert.equal($result.text(), 'Test', 'template based on script element works fine');
1950
});
2051

21-
2252
QUnit.module('clipboard');
2353

2454
QUnit.test('get text from clipboard', function(assert) {

0 commit comments

Comments
 (0)