简体   繁体   中英

Submit button confirm for delete not working in rails 3

I'm still new to rails and trying to understand something when deleting multiple items. When I click submit, it works and I can delete multiple items, however, it deletes regardless of my confirmation response.

I am using javascript to detect onclick event of my submit button, my code is:

$('.delete').on('click', function(){
    checked = countChecked();
    if (checked > 1) {
        confirm('Are you sure you want to delete these ' + checked + ' entries?');
    } else {
        confirm('Are you sure you want to delete this entry?');
    };
});

My submit button is:

<%= submit_tag "Delete Selected", { :class => 'delete'} %>

Why is the confirmation not doing the right thing? It deletes even if I press cancel...

Try this

$('.delete').on('click', function(){
    checked = countChecked();
    if (checked > 1) {
       return confirm('Are you sure you want to delete these ' + checked + ' entries?');
    } else {
       return confirm('Are you sure you want to delete this entry?');
    };
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM