Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'leave.bs.tab' event #14768

Closed
mtarnovan opened this issue Oct 10, 2014 · 5 comments
Closed

Add 'leave.bs.tab' event #14768

mtarnovan opened this issue Oct 10, 2014 · 5 comments
Milestone

Comments

@mtarnovan
Copy link

If the event of leaving a tab needs to be captured, the only way to do this at the moment is to check relatedTarget on show/shown events. A typical use-case would be checking if a form contained in a tab has unsaved changes to show a warning to the user when we switches to another tab. So instead of code like this:

  $('a[data-toggle="tab"][href="#my-tab-with-form"]').one('leave.bs.tab', checkDirty)

we have to do something like this:

  $('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
    if ($(e.relatedTarget).attr('href') == '#my-tab-with-form') {
      return checkDirty();
    }
  })

This also means that there's no way to only bind this once, because we emulate the leave event by checking the relatedTarget on show/shown.

@hnrch02
Copy link
Collaborator

hnrch02 commented Oct 10, 2014

hide and hidden would probably be more consistent names with all the other plugins' event names.

@mtarnovan
Copy link
Author

Because the events trigger on the tab anchors, not on the tab-panes, I think hide/hidden would not be a good fit.

@hnrch02
Copy link
Collaborator

hnrch02 commented Oct 10, 2014

It's either show and hide or enter and leave. Doesn't make sense to mix them up.

@mtarnovan
Copy link
Author

I see your point, and consistency across a framework is important, so I agree.

@cvrebert
Copy link
Collaborator

Fixed by #14772.

@cvrebert cvrebert added this to the v3.3.0 milestone Oct 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants