Skip to content

Commit 9a07b1b

Browse files
committed
luci-base: fix tab handling in modal dialogues
When adding tabs in modal dialogues, the old code of simply assigning s.tabs = this.tabs was problematic because it was an array of objects whose behaviour would cause a traceback when s.tab is called in e.g. a protocol handler Modal when it was reopened. Now verify the properties do not already exist before assigning them. This means one can define s.tab(...) in a Modal UI without a try block (which would even then sometimes fail). Signed-off-by: Paul Donald <newtwen+github@gmail.com>
1 parent fd8c8a4 commit 9a07b1b

File tree

1 file changed

+20
-2
lines changed
  • modules/luci-base/htdocs/luci-static/resources

1 file changed

+20
-2
lines changed

modules/luci-base/htdocs/luci-static/resources/form.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,8 +3339,26 @@ const CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection
33393339
m.section = section_id;
33403340
m.readonly = parent.readonly;
33413341

3342-
s.tabs = this.tabs;
3343-
s.tab_names = this.tab_names;
3342+
/* Clone tabs as both array and object. Otherwise calling renderMoreOptionsModal (reopening
3343+
the same Modal multiple times) results in errors when s.tab is called in the modal. This
3344+
allows Modal dialogues that declare new tabs to be opened multiple times without re-creating
3345+
tabs that 'already exist'. */
3346+
if (this.tabs) {
3347+
s.tabs = Array.from(this.tabs);
3348+
for (const key in this.tabs) {
3349+
if (Object.prototype.hasOwnProperty.call(this.tabs, key) && isNaN(Number(key))) {
3350+
s.tabs[key] = this.tabs[key];
3351+
}
3352+
}
3353+
} else {
3354+
s.tabs = undefined;
3355+
}
3356+
3357+
if (this.tab_names) {
3358+
s.tab_names = Array.isArray(this.tab_names) ? this.tab_names.slice() : Object.assign({}, this.tab_names);
3359+
} else {
3360+
s.tab_names = undefined;
3361+
}
33443362

33453363
this.cloneOptions(this, s);
33463364

0 commit comments

Comments
 (0)