-
-
Save kuntoaji/ce2adc5d1bbf82902c0d to your computer and use it in GitHub Desktop.
Javascript Alert For Unsaved Changes with Turbolinks, Jquery,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
change = function() { | |
$("form input, form textarea").change(function() { | |
$('a').click(function() { | |
confirm('Unsaved changes on the page. Are you sure?'); | |
}); | |
}); | |
}; | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ready = > | |
# your jquery code here | |
# page:load is fired at the end of the loading process. | |
$(document).ready(ready) | |
$(document).on('page:load', ready) | |
# page:change the page has been parsed and changed to the new version and on DOMContentLoaded | |
change = -> | |
$("form input, form textarea").change( -> | |
$('a').click( -> | |
confirm('Unsaved changes on the page. Are you sure?') | |
) | |
) | |
$(document).ready(change) | |
$(document).on('page:change', change) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment