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 b0277abce70..1e40ce13dd6 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -111,9 +111,10 @@ var FormRenderer = BasicRenderer.extend({ var $notebook = $(this); var name = $notebook.data('name'); if (name in state) { - $notebook.find('> ul > li > a[data-toggle="tab"]') - .eq(state[name]) - .click(); + var $page = $notebook.find('> ul > li').eq(state[name]); + if (!$page.hasClass('o_form_invisible')) { + $page.find('a[data-toggle="tab"]').click(); + } } }); }, diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index ae989f26165..f59c484b3c9 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -3778,5 +3778,53 @@ QUnit.module('Views', { form.destroy(); }); + + QUnit.test('do not activate an hidden tab when switching between records', function (assert) { + assert.expect(6); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + viewOptions: { + ids: [1, 2], + index: 0, + }, + res_id: 1, + }); + + assert.strictEqual(form.$('.o_notebook ul li:not(.o_form_invisible)').length, 2, + "both tabs should be visible"); + assert.ok(form.$('.o_notebook ul li:first').hasClass('active'), + "first tab should be active"); + + // click on the pager to switch to the next record + form.pager.$('.o_pager_next').click(); + assert.strictEqual(form.$('.o_notebook ul li:not(.o_form_invisible)').length, 1, + "only the second tab should be visible"); + assert.ok(form.$('.o_notebook ul li:not(.o_form_invisible)').hasClass('active'), + "the visible tab should be active"); + + // click on the pager to switch back to the previous record + form.pager.$('.o_pager_previous').click(); + assert.strictEqual(form.$('.o_notebook ul li:not(.o_form_invisible)').length, 2, + "both tabs should be visible again"); + assert.ok(form.$('.o_notebook ul li:nth(1)').hasClass('active'), + "second tab should be active"); + + form.destroy(); + }); }); });