0

I had a hyperlinks in the header. When user navigates from one header link to other i need to check whether page is in dirtied or not, if page is dirtied i need to show a modal which has ok and cancel buttons and on ok i need to navigate to the clicked header and on cancel i need to remain in the page. Below is the sample code I wrote.

Template:
<a href="#link1" id="link1"></a>
<a href="#link2" id="link1"></a>

HeaderView.js
..
..
ui {
  "link1" : "#link1",
  "link2" : "#link2",
},
events {
 "click #link1" : "navigateLink1"  
 "click #link2" : "navigateLink2"
}

navigateLink1 : function(e) {
    this.navigate(this.ui.link1, "#link1", true, e);
}
navigateLink2 : function(e) {
    e.preventDefault();
    this.navigate(this.ui.link2, "#link2", true, e);
}
navigate: function(uiElement, path, trigger, event) {
  e.preventDefault();

  if (model.isDirty() ) {
    // I need to send a callback for clicking on ok button
    this.callback = function() {
        event.trigger();// I am getting an error saying that event.trigger is not a function.
    }
     new ApplicationModal(model: {callback: this.callback});
  } else {
      app.router.navigate(path , {trigger: trigger});
  }
}

In ApplicationModal i am just executing the callback

I am getting an error saying that event.trigger is not a function while calling from the callback.Let me know how to navigate to the new page after e.preventDefault();

CNKR
  • 568
  • 5
  • 19
  • 1
    `event.trigger();` Where did you come up with such a reference..? jQuery event object does not have a trigger method. You can do [$element.trigger(event)](http://api.jquery.com/trigger/) where `$element` is a jQuery object. Can't you navigate using `app.router.navigate(path , {trigger: trigger});`..? You're passing `this.ui.link1`, and again passing `"#link1"` as another argument. Can't you access `"#link1"` from `this.ui.link1`..? – T J Nov 02 '15 at 09:29
  • @TJ Too bad you didn't write that as the answer. Seems like you are answering the question to me. – dchapman Nov 03 '15 at 15:10

0 Answers0