summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
Diffstat (limited to 'addons')
-rw-r--r--addons/web/static/src/js/core/widget.js10
-rw-r--r--addons/web/static/tests/core/widget_tests.js21
2 files changed, 28 insertions, 3 deletions
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();
}
},
diff --git a/addons/web/static/tests/core/widget_tests.js b/addons/web/static/tests/core/widget_tests.js
index 1c1c59f1d52..dc704abe274 100644
--- a/addons/web/static/tests/core/widget_tests.js
+++ b/addons/web/static/tests/core/widget_tests.js
@@ -450,6 +450,27 @@ QUnit.module('core', {}, function () {
parent.destroy();
});
+ QUnit.test("calling do_hide on a widget destroyed before being rendered", async function (assert) {
+ assert.expect(1);
+
+ const MyWidget = Widget.extend({
+ willStart() {
+ return new Promise(() => {});
+ }
+ });
+
+ const widget = new MyWidget();
+ widget.appendTo(document.createDocumentFragment());
+ widget.destroy();
+
+ // those calls should not crash
+ widget.do_hide();
+ widget.do_show();
+ widget.do_toggle(true);
+
+ assert.ok(true);
+ });
+
QUnit.test('start is not called when widget is destroyed', function (assert) {
assert.expect(0);
const $fix = $("#qunit-fixture");