summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammed Shekha <msh@odoo.com>2021-02-01 09:42:00 +0000
committerMohammed Shekha <msh@odoo.com>2021-02-17 11:00:19 +0000
commite695cb7c7d6eb989fd0540412d137410363a483f (patch)
treeb76acb5a833491b4ee7021b0a07312ea90188c8d
parente5d0cc6ff14d731f3b9fc5b8a446fab5d8e9990e (diff)
[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#66338 X-original-commit: a0b5ecd344d6ac79d8e4d194cfabf3d639259c73 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js7
-rw-r--r--addons/web/static/tests/views/form_tests.js38
2 files changed, 45 insertions, 0 deletions
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 c758c6a03fd..9a2f2620fb6 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -967,6 +967,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 89d1797589d..2cd9130353c 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: '<form string="Partners">' +
+ '<sheet>' +
+ '<field name="bar"/>' +
+ '<notebook>' +
+ '<page string="Foo" attrs=\'{"invisible": [["bar", "!=", false]]}\'>' +
+ '<field name="foo"/>' +
+ '</page>' +
+ '</notebook>' +
+ '</sheet>' +
+ '</form>',
+ 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);