summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/form
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-04-22 08:18:42 +0000
committerJulien Mougenot <jum@odoo.com>2020-04-22 15:11:02 +0000
commitdd9627120834961a546df3017fd7f2595e4762aa (patch)
tree49d76b854f97442686d775e13d69eca0938a6f1e /addons/web/static/src/js/views/form
parent97bc3717adb26bc459a61456228e8fae5f63fc2a (diff)
[FIX] web: handle empty notebooks in form views
Before this commit, when re-activating a previously active notebook tab, the form renderer would assume that a tab was actually active. However this does not happen if no tab is visible or defined and it results in a crash instead. Now, if no active tab is found, a default active tab (0 = first) is set. This only helps to prevent the crash and does not affect the current behaviour. closes odoo/odoo#50006 X-original-commit: 73e0c0a1395ebd0e2b4ac7f857c863a0358c5e17 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/form')
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js7
1 files changed, 5 insertions, 2 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 08819f79f57..1b672bdee19 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -213,9 +213,9 @@ var FormRenderer = BasicRenderer.extend({
for (const notebook of this.el.querySelectorAll(':scope div.o_notebook')) {
const name = notebook.dataset.name;
const navs = notebook.querySelectorAll(':scope .o_notebook_headers .nav-item > .nav-link');
- state[name] = [...navs].findIndex(
+ state[name] = Math.max([...navs].findIndex(
nav => nav.classList.contains('active')
- );
+ ), 0);
}
return state;
},
@@ -247,6 +247,9 @@ var FormRenderer = BasicRenderer.extend({
// We can't base the amount on the 'navs' length since some overrides
// are adding pageless nav items.
const validTabsAmount = pages.length;
+ if (!validTabsAmount) {
+ continue; // No page defined on the notebook.
+ }
let activeIndex = state[name];
if (navs[activeIndex].classList.contains('o_invisible_modifier')) {
activeIndex = [...navs].findIndex(