I have a form that spans several out-of-the-box Bootstrap Collapse panes. They toggle correctly on a mouse click - now I'd like to implement a way to open a closed pane via whatever event fires when tabbing from the last input of the currently open pane.
IOW, as I step thru the input fields of the open pane I can tab from one input to the next - when I tab from the last input the focus goes to the subsequent header region of the next pane. I'd like the act of tabbing to that header region to fire .collapse('toggle')
;
I've tried a few variations on:
$('#collapseAcct').focus(function () {
$('#collapseAcct').collapse('toggle');
});
and have also tried climbing the family tree with :parent
but haven't found the key. Structure of my panes:I'm using 3 panes where the unique identifier is a nested one layer deep in the div structure - pretty much the same as BS's documentation. E.G. struc of 1 pane:
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#createUserPanes" href="#collapseAcct">Account</a>
</div>
<div id="collapseAcct" class="accordion-body collapse">
<div class="accordion-inner">
<div>content</div>[and everything wraps out accordingly]
This should get you started: http://jsfiddle.net/Xbg4n/45/
The example doesn't use .collapse, but just .slideUp and .slideDown... should be easy enough to swap out with collapse but works for example purposes. What you are really getting out of this is the targeting, which I think is what you were mainly asking about. I also added a bit into this to cycle back to the first container, but stopped there. You should add better control over focus (avoid focus on anchor tags and force focus when cycling back to first container).
You didn't provide full HTML sample code, so I filled in the blanks:
the JS:
});
The CSS:
I had a situation where needed to make bootstrap panels behave like a form so open on focus or mouseover.
I just triggered the click event.
code:
You can use bootstrap collapse events
This event fires immediately when the show instance method is called.
This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).
This event is fired immediately when the hide method has been called.
This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to complete). Copy
example:
What about doing it the other way around, and opening the next accordion when the last input in the current accordion blurs :
And you did of course give all the elements unique ID's, and not all
collapseAcct