From 43ada221779dfa53fb04a4069aacd128555bb3fe Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Mon, 1 Feb 2021 09:42:00 +0000 Subject: [PATCH] [FIX] web: fix issue of notebook page with invisiblity modifier before this commit: when there is only one page in the notebook tag and there is a boolean field in form to show/hide that notebook page based on invisibility attrs, if we toggle boolean field notebook hides, that's OK but when we toggle boolean field again then notebook page is displayed but it is not active and due to that content of notebook page is not displayed. after this commit: when there is only one page in notebook and it has attrs for invisibilty, when we toggle boolean field to hide/show notebook page then notebook page as well as content is toggled. task-2449053 closes odoo/odoo#66582 X-original-commit: a0b5ecd344d6ac79d8e4d194cfabf3d639259c73 Signed-off-by: Aaron Bohy (aab) --- .../static/src/js/views/form/form_renderer.js | 7 ++++ addons/web/static/tests/views/form_tests.js | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+) 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 e1e9c5200a9..6173984878d 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -1000,6 +1000,13 @@ var FormRenderer = BasicRenderer.extend({ tab.$page.removeClass('active'); self.inactiveNotebooks.push(renderedTabs); } + if (!modifiers.invisible) { + // make first page active if there is only one page to display + var $visibleTabs = $headers.find('li:not(.o_invisible_modifier)'); + if ($visibleTabs.length === 1) { + self.inactiveNotebooks.push(renderedTabs); + } + } }, }); }); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 6752237898f..b3685b84128 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -875,6 +875,44 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('invisible attrs on notebook page which has only one page', async function (assert) { + assert.expect(4); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + assert.notOk(form.$('.o_notebook .nav .nav-link:first()').hasClass('active'), + 'first tab should not be active'); + assert.ok(form.$('.o_notebook .nav .nav-item:first()').hasClass('o_invisible_modifier'), + 'first tab should be invisible'); + + // enable checkbox + await testUtils.dom.click(form.$('.o_field_boolean input')); + assert.ok(form.$('.o_notebook .nav .nav-link:first()').hasClass('active'), + 'first tab should be active'); + assert.notOk(form.$('.o_notebook .nav .nav-item:first()').hasClass('o_invisible_modifier'), + 'first tab should be visible'); + + form.destroy(); + }); + QUnit.test('first notebook page invisible', async function (assert) { assert.expect(2);