Skip to content

Instantly share code, notes, and snippets.

@torsday
Last active August 29, 2015 14:13
Show Gist options
  • Save torsday/e79259021cf4c0967551 to your computer and use it in GitHub Desktop.
Save torsday/e79259021cf4c0967551 to your computer and use it in GitHub Desktop.
preventDefault() failure

preventDefault() failure

QUESTION: preventDefault() isn't preventing a sign out link getting called.

TESTED:

  • the block is getting called. I put in an alert() in the preventDefault block, and it indeed gets called

OTHER:

  • it does work for other links on the page, such as a next page link.

ReadingConnection.js

function promptForUnsavedWork() {
  if ($('#reading_connection_content').length > 0) {
    $('a').on('click', function (e) {
      $('.notebook_save_button_js').each(function(){
        if ($(this).attr('data-dirty') == 'true' && $(this).text() ==
"Save Your Answer"){
          $(this).closest('.connection_question_container').addClass('highlight');
          var confirmation_answer = confirm("You have unsaved work. Are
you sure you want to leave?");
          if (confirmation_answer) {
          } else {
            e.preventDefault();
          }
        }
      });

_student.html.erb

        <li class="sign_out gear_item"><%= link_to "Sign Out",
destroy_student_session_path, method: "delete", class: "gear_link", :id
=> "sign_out_link" %></li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment