Aashu Agarwal
Aashu Agarwal

Reputation: 173

how to capture bootstrap modal open/close event in meteor js

I am trying to capture bootstrap modal open/close event in meteor js to do some custom checks. I know how to do it in jquery:

$('#videoCallModal').on('shown.bs.modal', function () {
  // do something…
})

but since I also want to refer the context (this object), I want to do it in Template.template.events.

I tried something like, but the function was not invoked:

Template.videoCall.events = {
    'on #videoCallModal shown.bs.modal': function(e){
        e.preventDefault();

        console.log("modal open", this);
    }
}

Is there any other way to capture the close/open of modal in meteor js

Upvotes: 6

Views: 4709

Answers (2)

user3374348
user3374348

Reputation: 4101

The correct syntax is:

Template.videoCall.events({
  'shown.bs.modal #videoCallModal': function(e){
    /* ... */
  }
});

See this meteorpad.

Upvotes: 12

Peppe L-G
Peppe L-G

Reputation: 8345

I created peppelg:bootstrap-3-modal to provide a simple way to handle modals in Meteor. With it, you can use the created and destroyed callbacks (just as your used to in Meteor!), instead of the open and close events.

Upvotes: 6

Related Questions