From 01409c1d7b0050942ba5e53ff4f3bb927fd3eb51 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Mon, 15 Dec 2014 14:16:10 +0100 Subject: [PATCH] [FIX] web: openerpframework: replaceElement on multiple roots nodeset jquery's `replaceWith` function behaves differently between 1.8 and 1.9. This function is used by `renderElement` of the Odoo widget API and, when called on a template with multiple root nodes, will fail to replace the whole original nodeset by the new but instead will replace every node by the new nodeset. Sample: 1) Suppose a DOM containing
1
2
and a jquery nodeset [
1
,
2
] referring to the previous DOM part in a var named $oldel.; 2) suppose another jquery nodeset [
3
,
4
] in $el; $oldel.replaceWith($el) will result in "3434" in jquery 1.9.1 "34" in jquery 1.8.3 This issue particulary concerns us when the dom of a widget is not wrapped into single tag and when re-calling renderElement (triggering replaceElement). The fix is to wrap the element to be replaced ($oldel in the example) behind a div before calling replaceWith. --- addons/web/static/src/js/openerpframework.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/openerpframework.js b/addons/web/static/src/js/openerpframework.js index 29ad9160653..004ec2cb93a 100644 --- a/addons/web/static/src/js/openerpframework.js +++ b/addons/web/static/src/js/openerpframework.js @@ -688,7 +688,12 @@ openerp.Widget = openerp.Class.extend(openerp.PropertiesMixin, { var $oldel = this.$el; this.setElement($el); if ($oldel && !$oldel.is(this.$el)) { - $oldel.replaceWith(this.$el); + if ($oldel.length > 1) { + $oldel.wrapAll('
'); + $oldel.parent().replaceWith(this.$el); + } else { + $oldel.replaceWith(this.$el); + } } return this; },