Antarr Byrd
Antarr Byrd

Reputation: 26151

Button in modal not working

I'm trying to create a modal that confirms that you really want to delete a user. Everything seems to work except for when you click on the the '#confirm' button within the modal. The form for the button that was originally clicked on should be submitted but it is not happening. It doesn't appear that the on('click') for #confirm is be fired because I cannot see my log message either.

_actions.html.slim

span.member_action.create
  = link_to 'Add New User', new_account_member_path(@account), class: "btn add-user"
#group_member_actions
  span.member_action.reset
    = link_to 'Reset Password', '#', class: 'btn'
  span.member_action.clone
    = link_to 'Clone', '#', class: 'btn'
  span.member_action.delete
    = submit_tag 'Delete', class: 'btn delete-white'

/! Modal Dialog
#confirmDelete.modal.fade aria-hidden="true" aria-labelledby="confirmDeleteLabel" role="dialog"
  .modal-dialog
    .modal-content
      .modal-header
        button.close aria-hidden="true" data-dismiss="modal" type="button"  ×
        h4.modal-title
          | Delete User
      .modal-body
        p
          | Are you sure you want to delete this user?
      .modal-footer
        button.btn.btn-default data-dismiss='modal' type='button' Cancel
        button#confirm.btn.btn-danger type='button' Delete



javascript:
  $('#confirmDelete').on('show', function() {
    $('#confirm').on('click', function(){
      console.log('you clicked confirm');
      $('#delete-member').submit();
    });
  });
  $('.delete-white').on('click', function(e){
    e.preventDefault();
    $('#confirmDelete').data('id', $(this).data('id')).modal('show');
  });

css:
  .modal.in .modal-dialog { margin: 10% auto;} 

index.html.slim

= form_tag remote_destroy_account_members_path(@account), id: 'delete-member', method: :delete do
  = render partial: 'shared/users_title', locals: { hide_user_nav: false }

Upvotes: 0

Views: 856

Answers (1)

Antarr Byrd
Antarr Byrd

Reputation: 26151

javascript:
    $('#confirm').on('click', function(){
      console.log('you clicked confirm');
      $('#delete-member').submit();
    });
  $('.delete-white').on('click', function(e){
    e.preventDefault();
    $('#confirmDelete').data('id', $(this).data('id')).modal('show');

Upvotes: 1

Related Questions