PrevenDefault(); alternative when using data-route?

14 views
Skip to first unread message

ch...@hiplogiq.com

unread,
Oct 14, 2014, 3:51:01 PM10/14/14
to batm...@googlegroups.com
Hello All,

When a user makes a change to a page and then tries to navigate away from the page I need to cancel the redirect and display some warnings. Since using data-route already prevents the DOM default, is there a way that I can do the same thing when using data-route to an anchor tag?

Any help is much appreciated,
Chase

chase...@gmail.com

unread,
Oct 31, 2014, 11:36:54 AM10/31/14
to batm...@googlegroups.com
Basically, I need to cancel the redirect.

Robert Mosolgo

unread,
Oct 31, 2014, 1:50:46 PM10/31/14
to batm...@googlegroups.com
I don't know of a built-in way. No joke, one time I had to do this, so I overrode (sp?) `Batman.redirect`  inside a Batman.View, something like this:

class MyApp.WhateverView extends Batman.View
  viewWillAppear
: ->
   
@oldBatmanRedirect = Batman.redirect
   
Batman.redirect = =>
     
if confirm("Are you sure?")
       
@oldBatmanRedirect.apply(null, arguments)

  viewWillDisappear
: ->
   
Batman.redirect = @oldBatmanRedirect
 


(data-route delegates to Batman.redirect: https://github.com/batmanjs/batman/blob/master/modules/view_layer/bindings/route_binding.coffee#L32)

hope that helps,

robert

chase...@gmail.com

unread,
Oct 31, 2014, 5:40:15 PM10/31/14
to batm...@googlegroups.com
Yes thank you so much Robert! Man, I thought you had abandoned this group for good! Glad to see you're still around providing help where you can, I really appreciate it.

Chase

Reply all
Reply to author
Forward
0 new messages