Skip to content

Commit

Permalink
Fix lost aspnet.createComponent calls (T810336) (#9540)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyMartynov authored Sep 2, 2019
1 parent dd6ed7a commit e5989f4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
19 changes: 11 additions & 8 deletions js/aspnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
}
})(function($, setTemplateEngine, templateRendered, Guid, validationEngine, iteratorUtils, extractTemplateMarkup, encodeHtml) {
var templateCompiler = createTemplateCompiler();
var pendingCreateComponentRoutines = [ ];

function createTemplateCompiler() {
var OPEN_TAG = "<%",
Expand Down Expand Up @@ -123,19 +124,21 @@
}

function createComponent(name, options, id, validatorOptions) {
var render = function(_, container) {
templateRendered.remove(render);

var selector = "#" + id.replace(/[^\w-]/g, "\\$&"),
$component = $(selector, container)[name](options);
var selector = "#" + id.replace(/[^\w-]/g, "\\$&");
pendingCreateComponentRoutines.push(function() {
var $component = $(selector)[name](options);
if($.isPlainObject(validatorOptions)) {
$component.dxValidator(validatorOptions);
}
};

templateRendered.add(render);
});
}

templateRendered.add(function() {
var snapshot = pendingCreateComponentRoutines.slice();
pendingCreateComponentRoutines = [ ];
snapshot.forEach(function(func) { func(); });
});

return {
createComponent: createComponent,

Expand Down
34 changes: 32 additions & 2 deletions testing/tests/DevExpress.aspnet/aspnet.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@


$("#qunit-fixture").html(
'<div id="popop1">' +
'<div id="popup1">' +
'</div>' +

'<script id="popup1_contentTemplate" type="text/html">' +
Expand All @@ -429,7 +429,7 @@
'</script>'
);

$("#popop1").dxPopup({
$("#popup1").dxPopup({
contentTemplate: $("#popup1_contentTemplate"),
visible: true
});
Expand All @@ -452,4 +452,34 @@
}
});

QUnit.test("T810336", function(assert) {
aspnet.setTemplateEngine();

window.__createButton = function(buttonID) {
DevExpress.aspnet.createComponent("dxButton", { text: buttonID }, buttonID);
};

try {
$("#qunit-fixture").html(
'<div id="popup1"></div>' +
'<script id="popup1_contentTemplate" type="text/html">' +
' <div id="b1"></div><% __createButton("b1") %>' +
' <div id="b2"></div><% __createButton("b2") %>' +
'</script>'
);

$("#popup1").dxPopup({
contentTemplate: $("#popup1_contentTemplate"),
visible: true
});

assert.ok($("#b1").dxButton("instance"));
assert.ok($("#b2").dxButton("instance"));

} finally {
setTemplateEngine("default");
delete window.__createButton;
}
});

}));

0 comments on commit e5989f4

Please sign in to comment.