Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call an event on Bootstrap panel expand

I am working on a flow where we are using Bootstrap styled accordion (NOT jQuery UI accordion). The requirement is to call a service when the user expands the accordion. Here's the HTML:

<div class="accordion-dashboard">
    <div class="panel-group" id="accordion">
        <div class="panel panel-default">
            <div class="panel-heading  row-white" data-toggle="collapse" data-parent="#accordion" href="#runtimeValue">                 
                <table>
                    <tr>
                        <td><span class="badge blue">A</span></td>
                        <td><strong>Aenean ultricies est lorem,id feugiat velit euismod ut.Nullam inia.Prasent vel nu Sed ante mauris, eu lacus..</strong></td>
                        <td><i class="icon8 icon-paperclip"></i></td>
                        <td><span class="time">5 mins</span></td>
                    </tr>                    
                </table>                        
            </div>
            <div id="runtimeValue" class="panel-collapse collapse ">
                <div class="panel-body">

                    <div class="row">
                        <div class="col-lg-9 col-lg-offset-1">
                            <table>
                                <tr>
                                    <td class="text-muted">By</td>
                                    <td><img width="24px" src="images/company-logo.png"> Company Admin</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">On</td>
                                    <td class="text-muted">Friday- 7 Aug 2014, 9.00PM</td>
                                </tr>
                                <tr>
                                    <td><i class="icon8 icon-paperclip"></i></td>
                                    <td>dummyfile.pdf</td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <h5>Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.</h5>
                                        <p>Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.</p>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-lg-1 pull-right">
                            <span data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="btn-close icon8"></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>    
</div>

HREF attribute and the correspoding id attributes will be decided at runtime and I am aware of the pattern of them. One approach could be binding an event on click of the accordion, but I want to have it as a last resort.

Is there any other way I can call a service when the user clicks and expands the accordion?

like image 994
Pramod Karandikar Avatar asked Nov 05 '14 05:11

Pramod Karandikar


People also ask

How do you expand and collapse in Bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How do you make a Div collapsible?

The . collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.

What is Aria expanded false in Bootstrap?

If the collapsible element is closed by default, the attribute on the control element should have a value of aria-expanded="false" . If you've set the collapsible element to be open by default using the show class, set aria-expanded="true" on the control instead.


1 Answers

You can use :-

$('#accordion').on('show.bs.collapse', function () {
       //call a service here 
});
like image 147
Rushee Avatar answered Sep 22 '22 04:09

Rushee