Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:15:15+00:00 2026-06-04T05:15:15+00:00

I have a form where I create a model and I want a dialoge

  • 0

I have a form where I create a model and I want a dialoge box to appear if the user navigates away from the page, unless they click the save/create button.

I have this javascript code that works anytime the user leaves the page; meaning this dialoge still appears when the user clicks save/create.

#javascripts/workouts.js.coffee
window.confirmExit = () ->
  "Your changes will not be saved.";

#workouts/new.html.haml
= render 'form'
:javascript
  window.onbeforeunload = confirmExit

#workouts_form.html.haml
= simple_form_for(@workout) do |f|
# some input fields
= f.button :submit

Now I know that I only want the confirm exit called if the submit button is not clicked, but I am not sure how to go about doing this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:15:17+00:00Added an answer on June 4, 2026 at 5:15 am

    So I figured it out, at least it works for chrome and safari although right now I am under the impression that it will not work for ie. What I did was create a boolean that is set to false and only set to true when the submit button is selected.

    #javascripts/workouts.js.coffee
    window.submitButtonClicked = false
    window.confirmExit = () ->
      if window.submitButtonClicked
        null
      else
        "Your changes will not be saved."
    
    $(document).ready ->
      $('#target').submit ->
        window.submitButtonClicked = true
    
    #workouts/new.html.haml
    :javascript
      window.onbeforeunload = confirmExit
    
    #workouts_form.html.haml
    #target
      = simple_form_for(@workout) do |f|
        # some input fields
        = f.button :submit
    

    I hope this helps anyone who was curious. Note that the #target line is actual haml and not a comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MVC, ASP.Net application and I want to create a dialog form.I
So I have a form that I want the user to use to update
I have a model named Post. I want to use a modal form to
I have form @using (Html.BeginForm(Create, StoreManager)) { @Html.ValidationSummary(true) //etc.. } User uploads images to
I have a page where the user can update a form by clicking on
if i have created a view model and have a partial form that is
I have a form which I create manually (a lot of JavaScript in it...).
i have create a form (so it's PHP and HTML hybrid-code). it has ability
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have been tasked to create a form designer application in Windows Forms. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.