1

I'm wondering how to exactly change tab (core mage/tabs widget) programmatically. Docs say that I can use both activate and enable functions for that: http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/widgets/widget_tabs.html

Unfortunately, no one is recognized.

Tabs are initialized as follows:

var tabs = $('.tabs'); tabs.tabs({ openedState: 'active-tab' }); 

Initialization and other base things work fine. The issue occurs when I would like to change tab programmatically:

tabs.activate('3'); // Uncaught TypeError: tabs.activate is not a function 

I'm not sure what I am doing wrong.

2
  • How are you adding your JS? e.g via XML or Require? If you're using require what dependencies have you added? Commented Sep 28, 2017 at 13:44
  • JS is added by data-mage-init attribute in phtml file. This is my dependencies in define/require block: define([ 'jquery', 'matchMedia', tabs'], function ($, mediaCheck, tabs) { .. }); Commented Sep 28, 2017 at 14:13

2 Answers 2

1

Inside vendor/magento/module-review/view/frontend/web/js/process-reviews.js:40 they are used like this:

$('.selector').tabs('activate', index); 
3
  • Hey, @BenCrook thanks for your response! I missed it. This time code goes further without any errors, unfortunately still nothing happen with tabs. I use debugger to check how browser interpreted this code: tabs.tabs('activate' 114); - just go ahead, as if nothing was inside there. Commented Sep 28, 2017 at 14:22
  • Try adding a comma after 'activate'. If that still doesn't work to test the methods are working try $('.selector').tabs('destroy'). That should fully destroy the tabs. Commented Sep 28, 2017 at 14:26
  • 1
    I have changed initialization method and finally, your approach starts working :) thanks! Commented Oct 3, 2017 at 8:20
0
$('.product.data.items').tabs('activate', index); 

index starting from 0

also you can check index by below code

$('.product.data.items [data-role="content"]').each(function (index) { alert(this.id+index); }) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.