fix: Remember active tab for a document in a browsing session
This commit is contained in:
parent
3f2901d837
commit
ee7cb22cd6
3 changed files with 22 additions and 4 deletions
|
|
@ -1840,6 +1840,15 @@ frappe.ui.form.Form = class FrappeForm {
|
|||
});
|
||||
});
|
||||
}
|
||||
set_active_tab(tab) {
|
||||
if (!this.active_tab_map) {
|
||||
this.active_tab_map = {};
|
||||
}
|
||||
this.active_tab_map[this.docname] = tab;
|
||||
}
|
||||
get_active_tab() {
|
||||
return this.active_tab_map && this.active_tab_map[this.docname];
|
||||
}
|
||||
};
|
||||
|
||||
frappe.validated = 0;
|
||||
|
|
|
|||
|
|
@ -336,11 +336,14 @@ frappe.ui.form.Layout = class Layout {
|
|||
if (visible_tabs && visible_tabs.length == 1) {
|
||||
visible_tabs[0].parent.toggleClass('hide show');
|
||||
}
|
||||
this.set_first_tab_as_active();
|
||||
this.set_tab_as_active();
|
||||
}
|
||||
|
||||
set_first_tab_as_active() {
|
||||
if (this.tabs.length && !this.frm.active_tab) {
|
||||
set_tab_as_active() {
|
||||
let frm_active_tab = this?.frm.get_active_tab?.();
|
||||
if (frm_active_tab) {
|
||||
frm_active_tab.set_active();
|
||||
} else if (this.tabs.length) {
|
||||
// set first tab as active when opening for first time, or new doc
|
||||
let first_visible_tab = this.tabs.find(tab => !tab.is_hidden());
|
||||
first_visible_tab && first_visible_tab.set_active();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export default class Tab {
|
|||
this.fields_list = [];
|
||||
this.fields_dict = {};
|
||||
this.make();
|
||||
this.setup_listeners();
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +80,6 @@ export default class Tab {
|
|||
set_active() {
|
||||
this.parent.find('.nav-link').tab('show');
|
||||
this.wrapper.addClass('active');
|
||||
this.frm.active_tab = this;
|
||||
}
|
||||
|
||||
is_active() {
|
||||
|
|
@ -89,4 +89,10 @@ export default class Tab {
|
|||
is_hidden() {
|
||||
return this.wrapper.hasClass('hide');
|
||||
}
|
||||
|
||||
setup_listeners() {
|
||||
this.parent.find('.nav-link').on('shown.bs.tab', () => {
|
||||
this?.frm.set_active_tab?.(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue