fix: Set first visible tab as active

This commit is contained in:
Suraj Shetty 2022-06-17 16:16:58 +05:30
parent 6d6a67e9e3
commit 05ea37c779
3 changed files with 7 additions and 8 deletions

View file

@ -575,8 +575,6 @@ frappe.ui.form.Form = class FrappeForm {
this.$wrapper.trigger('render_complete');
this.layout.set_first_tab_as_active(switched || this.cscript.is_onload);
if(!this.hidden) {
this.layout.show_empty_form_message();
}

View file

@ -123,7 +123,7 @@ frappe.ui.form.Layout = class Layout {
if (this.is_tabbed_layout()) {
// add a tab without `fieldname` to avoid conflicts
let default_tab = {label: __('Details'), fieldtype: "Tab Break"};
let default_tab = {label: __('Details'), fieldtype: "Tab Break", fieldname: "__details"};
let first_tab = this.fields[1].fieldtype === "Tab Break" ? this.fields[1] : null;
if (!first_tab) {
this.fields.splice(1, 0, default_tab);
@ -336,12 +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();
}
set_first_tab_as_active(switched) {
if (this.tabs.length && (switched || !this.frm.active_tab)) {
set_first_tab_as_active() {
if (this.tabs.length && !this.frm.active_tab) {
// set first tab as active when opening for first time, or new doc
this.tabs[0].set_active();
let first_visible_tab = this.tabs.find(tab => !tab.is_hidden());
first_visible_tab.set_active();
}
}

View file

@ -87,7 +87,6 @@ export default class Tab {
}
is_hidden() {
this.wrapper.hasClass('hide')
&& this.parent.hasClass('hide');
return this.wrapper.hasClass('hide');
}
}