powmedia / backbone.bootstrap-modal

Bootstrap Modal wrapper for use with Backbone.
MIT License
183 stars 97 forks source link

Events in the view #40

Open Veid opened 11 years ago

Veid commented 11 years ago

The example in the readme about events in the view doesn't seem to work, as the alert never shows:

var view = new Backbone.View({
    initialize: function () {
        this.bind("ok", okClicked);
    },

    okClicked: function (modal) {
        alert("Ok was clicked");
        modal.preventClose();
    }
});

var modal = new Backbone.BootstrapModal({ content: view }).open();

This is the related code in backbone.bootstrap-modal.js:

'click .ok': function(event) {
  event.preventDefault();
  this.trigger('ok');

  if (this.options.content && this.options.content.trigger) {
    console.log("Content:", this.options.content);
    console.log("Modal  :", this);
    this.options.content.trigger('ok', this);
  }

  if (this.options.okCloses) {
    this.close();
  }
}

I'm rather new to Backbone so I don't fully get what's happening with the context when this.options.content.trigger('ok', this) is called.

If someone could explain this to me and nudge me in the right direction to get the above example working, that would be great!

Thanks!

acrawly commented 8 years ago

+1 for this