-
-
Notifications
You must be signed in to change notification settings - Fork 79k
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
Dropdown add events #1343
Comments
Seems odd - what's the usecase? |
do custom page ajax load on user click. |
It's better to have a global lib that attaches events to links with data-remote attribute. That's how Rails does it => https://github.com/rails/jquery-ujs/blob/master/src/rails.js#L53 It also gives you all the callbacks you want. You can obviously use that outside of Rails, it's not framework specific. |
just listen to the element's click event then - nothing different between that and having a shown event |
+1 Use case: Facebook style notification menu. I want to set a timeout when the menu is opened, and clear the timeout if the menu closes before a certain amount of time has passed. |
+1 I have a very similar use case and would love to see this added! @fat: might work for shown, but not for hidden as you can click anywhere to hide the dropdown. |
I tried listening to the click event, but it seems that bootstrap returns false in the function that shows the dropdown, so even that is not possible. Perhaps this issue should be re-opened. |
+1 to open this issue again. event.preventDefault() seems to be a better option. |
I would just like to see an event for dropdown close. |
By the way, a friend suggested I use .on() instead of .click(), and that did the trick. |
+1 I want a event for dropdown close as well. The use case is a dropdown with check boxes and a submit button at the end. I want to submit the form if the user clicks the submit button OR if he closes the dropdown. |
+1 Click does seem to have some issues with the dropdown, a set of events could be handy for all sort of things, as well as staying consistant across similar bootstrap elements. Using on/live/click doesn't work on my dropdowns, seems that the click event isn't bubbling past the dropdown toggle. The dblclick event still works (as useful as that is). Edit: Using both the mousedown and mouseup commands together is a workaround for this. |
+1 Another use case: I want to update information on the dropdown when it's opened, pretty much like the tag dropdown on gmail. The checkboxes are already there, but it may be expensive to update them all the time. |
+1 An event for dropdown close would be great. An use case: to disable the dropdown itself once the user already read its content. |
@fat can we finally reopen this ticket please look at all the +1s! Thanks |
Best way I found to solve this was to remove the data-toggle from the element, and then re-add on your click event. This worked for what I was doing with it which was to load the drop down via ajax so my specific event only needed to be called once. $(document).on("click", ".class", function(event) {
// Ajax actions here
$(this).attr("data-toggle", "dropdown").click();
}); |
I'd also like to see a 'shown' event for the dropdown so I can set focus to a field |
+1 This would provide a quick and easy way to focus on a form field upon opening. |
+1 Use case: reset input fields in login drop down on close so it doesn't have crud from previous login attempt |
+1 use case: trigger an ajax load on display |
+1 Use case: need to fire an analytics ajax call when a user opens and closes the menu. |
+1 This would provide a quick and easy way to focus on a form field upon opening. |
+1 I would like to know when the menu has been dismissed. |
+1 |
+1. listen for click is not enought. would be nice to have show/open events . |
+1 use case: also to trigger an ajax load on display to load dynamic data in to menu. I'm really surprised there are no events for this plugin. |
This only loads the ajax request on the first click for each item for me. $(document).on("click", ".class", function(event) { What do I need to do to load the ajax request on each time the drop down menu is toggled? |
+1 |
+1 |
+1 |
@jbranc ha! Was exactly my use case. |
@elado looks like a feature in high demand! FWIW here is a partial workaround. gets rid of it on open, but it still comes back while the menu is open if they hover over again. $('.dropdown').on('click', function(e) {
$('[rel=tooltip]').tooltip('hide');
}); |
+1 |
+1 |
+1 for focusing an input inside the dropdown upon being shown. |
Use case: User clicks dropdown trigger, dropdown opens immediately with a indeterminate progress bar, AJAX call is made to populate contents dynamically. I need access to a "closed" event, so I can repopulate the contents of the dropdown to the original indeterminate progress bar for subsequent requests. |
+1 - dropdown contains options (checkboxes etc). Save settings on close event. |
+1 I would like to be able to perform an action once the dropdown has been displayed. |
I needed this today (again). |
+1 I read the docs about events and naturally assumed that this event would exist. I've wasted 20 minutes trying to figure out why it wasn't working only to discover there is no event! A simple onclick is not the same as you also have to check if it's an open or a close click and check whether the drop-down has been rendered yet - all things which a show event would encapsulate. |
would be great to have an event fired on dropdown hide/close. not having it is making my development much more difficult |
Stil nothing after a year? |
dropdown hide/close will be very useful |
+1 There are many use-cases for this, and given how trivial the addition is compared to the added benefit, it seems a no-brainer. |
+1. Need this badly for my minishopping cart. |
+1 |
+1
This would be extremely useful for me. |
+1
EDIT: I finally found the "shown" event and got it working. Please see http://twitter.github.io/bootstrap/javascript.html#modals and scroll a little ways down to Events. If you're getting a "modal is not a function" error like I was, check to make sure you aren't loading jQuery AFTER bootstrap.js. I didn't think I was until I realized that I had copy/pasted a second jQuery link in for a plugin. EDIT 2: I realize now that this is specifically about dropdown menus. Feel free to ignore this entire comment if what I said doesn't apply to dropdowns at all. |
The problem with #1343 (comment) is that you can close the dropdown by clicking on any other part of the document. So just listening for clicks on the toggle element won't help. |
@tacone but the dropdown must setup a listener for that click outside the document, right? Why not just fire an event from inside there? |
@davewasmer let's also setup a listener for key presses then, shall the nyancat accidentally land on your escape key. Here's my workaround. Ugly, but less ugly than hacking the core. |
@tacone thanks for the example code, but I don't see the ugliness of adding this to the core. Not only would the code be cleaner (just adding a trigger to the existing listeners), it would make the interface consistent with the other JS UI components (i.e. modal, scrollspy, tabs, alerts, collapse, and carousel all fire events). |
+1 |
+1 ... trying to disable tooltips on the link when dropdown is toggled. |
@cvrebert, thank you! |
It would be very usefult if Dropdown would have some events like Modal have (show, shown, hide, hidden)
The text was updated successfully, but these errors were encountered: