From 953fb092636b9919aaa6c6a6cfaffd003ba951d5 Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Tue, 22 Dec 2020 16:59:46 +0000 Subject: [FIX] web,mail: Call on_attach_callback when appending content Before this commit, the form renderer would call "on_attach_callback" only when the whole _render process was over. The problem was that this process is asynchronous and this callback should be invoked as soon as the widgets are appended. As such, any asynchronous operation is performed before appending the content in a new function "__renderView". Task 2346540 closes odoo/odoo#60791 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/views/basic/basic_renderer.js | 4 +++- addons/web/static/src/js/views/form/form_renderer.js | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js index 16ecc473915..a03b9b41a77 100644 --- a/addons/web/static/src/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -684,7 +684,7 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { if (this._isInDom) { for (const handle in this.allFieldWidgets) { this.allFieldWidgets[handle].forEach(widget => { - if (widget.on_attach_callback) { + if (!utils.isComponent(widget.constructor) && widget.on_attach_callback) { widget.on_attach_callback(); } }); @@ -694,6 +694,8 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { widget.on_attach_callback(); } }); + // call on_attach_callback on child components (including field components) + WidgetAdapterMixin.on_attach_callback.call(this); } }, /** diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js index b6e1593b215..c758c6a03fd 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -1029,7 +1029,7 @@ var FormRenderer = BasicRenderer.extend({ var $form = this._renderNode(this.arch).addClass(this.className); delete this.defs; - return Promise.all(defs).then(function () { + return Promise.all(defs).then(() => this.__renderView()).then(function () { self._updateView($form.contents()); if (self.state.res_id in self.alertFields) { self.displayTranslationAlert(); @@ -1042,6 +1042,14 @@ var FormRenderer = BasicRenderer.extend({ $form.remove(); }); }, + /** + * Meant to be overridden if asynchronous work needs to be done when + * rendering the view. This is called right before attaching the new view + * content. + * @private + * @returns {Promise} + */ + async __renderView() {}, /** * This method is overridden to activate the first notebook page if the * current active page is invisible due to modifiers. This is done after -- cgit v1.2.3