Skip to main content

beforeChange

fires before changing the active tab

beforeChange: (id: string, prev: string) => boolean | void;

Parameters:

  • id: string - the id of a newly active tab
  • prev: string - the id of a previously active tab

Returns:

Return false to prevent an active tab from being changed; otherwise, true.

Example

tabbar.events.on("beforeChange", function(id, prev){
console.log("The " + prev + " active tab will be changed");
return false;
});

Related sample: Tabbar. Events

For instance, you can define the logic for blocking the ability to switch between even tabs:

tabbar.events.on("beforeChange", (id, prev) => {
const tabIndex =
tabbar.config.views.findIndex(tabObj => tabObj.tab === tabbar.getCell(id).config.tab);
if (tabIndex % 2 === 1) return false;
});

Change log:

added in v7.3