Skip to main content

Helper method to select/activate a kendo.ui.TabStrip tab by name.

/**
 * Helper method to select/activate a kendo.ui.TabStrip tab by name.
 * Does nothing if the tab is already selected.
 *
 * @param {kendo.ui.TabStrip} kendoTabStrip The kendo.ui.TabStrip widget instance.
 * @param {string} tabName The tab name to select.
 */
function selectedKendoTabStripTabByName(kendoTabStrip, tabName) {
    const selectedTab = kendoTabStrip.select();
    const currentlySelectedTabName = selectedTab.text();
    const tabStripItems = kendoTabStrip.tabGroup.children("li");

    [].forEach.call(tabStripItems, function(element, index) {
        const elementText = element.innerText;
        if (elementText === tabName) {
            if (currentlySelectedTabName !== elementText) {
                console.debug("[selectedKendoTabStripTabByName] selecting tabName:", tabName);
                kendoTabStrip.select(index);
            } else {
                console.debug("[selectedKendoTabStripTabByName] tabName already selected:", tabName);
            }
        }
    });
}