If a user is on a form page, I am trying to throw a confirm message if they navigate away without clicking the update button.
The coffeescript code I am using is as follows
# used to detect if a user is navigating off a page
if form_click == true
window.onbeforeunload = ->
"You have unsaved data! do you really want to exit?"
If I use if 1 ==1 or 1 ==2 as a test case, it works perfectly fine. However, I am having diffculty in sending a variable from the link_to code to set form_click.
I have tried the following
<%= f.button :button, :class => 'btn-primary',
data: {form_click: true},
remote: true %>
But I am not able to pass the variable to the coffeescript code. I am definitely not proficient with javascript and coffeescript, as this probably shows, and would be grateful of any advice on how to resolve this would be much appreciated