Skip to content

beforeClose and stopping close being called #186

Closed
dominicglenn opened this Issue Jul 15, 2012 · 4 comments

4 participants

@dominicglenn

I'm not entirely sure if the functionality already exists in Marionette, but the ability to either have beforeClose stop a view being closed, or a separate method to handle this would be useful.

The use case for this would be unsaved models etc, if you are about to close an ItemView that has unsaved changes made to the model, you'd be able to prompt the user if they want to cancel the close operation since the model is unsaved.

@derickbailey
Marionette.js member

i agree with the desired behavior, but i'm not sure i agree with the suggested implementation.

it seems to me that the best idea would be to have your DOM click event or whatever is handlign the "close" button, make this check and only call close() on the view if it's really ready to close:

Marionette.ItemView.extend({

  events: {
    "click #close": "closeClicked"
  },

  closeClicked: function(e){
    if (... some check to see if this thing can be closed...){
      this.close();
    }
  }

});

Does that work for your needs, or is there a more specific scenario that you are trying to facilitate?

@joezimjs
joezimjs commented Oct 4, 2012

I agree with this @derickbailey on this. I don't see why this isn't being checked before close is being called. Maybe if you can explain the situation in a way that helps us understand why that isn't a valid option, that might help.

@derickbailey
Marionette.js member

this seems to be a dead request, so i'm closing it.

@rally25rs

I think the common use case for this would be having a main navbar/header that has links in it, for example href="#/" to go "Home"

Then the app is currently on an ItemView, perhaps at "#/myitem"

If I click the Home link I need to prompt the user to save the data on their ItemView if it has changes.
There seems to be no built-in way to do this in Backbone or Marionette.

The route, controller, and view all have no way to cancel the navigation action based on the result of a confirm("discard your changes?") call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.