jellekralt / Responsive-Tabs

Responsive Tabs is a jQuery plugin that provides responsive tab functionality. The tabs transform to an accordion when it reaches a CSS breakpoint. You can use this plugin as a solution for displaying tabs elegantly on desktop, tablet and mobile.
http://jellekralt.github.io/Responsive-Tabs/
MIT License
531 stars 228 forks source link

Click callback: is it possible to avoid navigating away at this point? #126

Closed chimos closed 7 years ago

chimos commented 7 years ago

Hi, with Responsive-Tabs, when the user clicks on another tab, and there are unsaved changes, I need to show a confirm box similar to "You could loose changes... are you sure? Ok + Cancel". The problem is that I don't know how to stop the loading / activation of the new tab, when the user choses to cancel (and stay in the current tab).

I tried with return false; without success:

            $('#horizontalTab').responsiveTabs({
                rotate: false,
                startCollapsed: 'accordion',
                collapsible: 'accordion',
                setHash: false,
                active: '".$tab_idx."',
                disabled: '".$tabs_disabled."',
                click: function(event, tab) {
                    if ( $('#horizontalTab').hasClass('unsaved_state') ) {
                        var result = confirm('You could loos changes.. Are you sure?');
                        if (!result) {
                            return false;
                        }
                    }
                }
            });

I couldn't find any info about this in docs or examples. Any help would be appreciated. Thank you!

jellekralt commented 7 years ago

This is not something that is currently supported. I would be open to a solution with something live event.preventDefault(), but that would be something for the future.

chimos commented 7 years ago

Ok, thanks for your answer. I ended up modifying de original .js file in a not nice/clean way, in order to get it working ASAP. So, you can consider this issue closed for me. Thanks again