From 7e45dd0b8fc2d94eb992e67206f18cd4400f4a33 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 10 Feb 2021 09:03:08 +0000 Subject: [FIX] web: call do_hide/do_show on a destroyed widget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, calling do_hide/do_show/do_toggle on a widget that had been destroyed before being rendered crashed (because this.$el was undefined). Obviously, calling those methods in this situation is useless, but with asynchronous code, it might happen that you call them in an handler, and they have been destroyed meanwhile. This commit checks if this.$el is set before accessing it to avoid the crash. closes odoo/odoo#65889 X-original-commit: 320c29f5b37d4f02b4d5f7b1b6ff64462b000c92 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/js/core/widget.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/core') diff --git a/addons/web/static/src/js/core/widget.js b/addons/web/static/src/js/core/widget.js index a089f8876fe..8b827147450 100644 --- a/addons/web/static/src/js/core/widget.js +++ b/addons/web/static/src/js/core/widget.js @@ -214,13 +214,17 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * Hides the widget */ do_hide: function () { - this.$el.addClass('o_hidden'); + if (this.$el) { + this.$el.addClass('o_hidden'); + } }, /** * Displays the widget */ do_show: function () { - this.$el.removeClass('o_hidden'); + if (this.$el) { + this.$el.removeClass('o_hidden'); + } }, /** * Displays or hides the widget @@ -229,7 +233,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { do_toggle: function (display) { if (_.isBoolean(display)) { display ? this.do_show() : this.do_hide(); - } else { + } else if (this.$el) { this.$el.hasClass('o_hidden') ? this.do_show() : this.do_hide(); } }, -- cgit v1.2.3