ONYX
ONYX

Reputation: 5859

prevent click event with confirm dialog and then continue operation

I'm trying to do a dialog before deletion so I've added e.preventDefault() from deletion happening straight away but when I'm in the YES function I want to simulate the function to continue it's click event with return true and e.preventDefault() to be false. How do I continue the click event to do it's operation?

<script type="text/javascript">
    $(function() {
        $('#delete_registry').on('click', function(e) {

            e.preventDefault();

            alertify.confirm('Delete Registry', 'Are you sure you want to delete your registry, all data will be lost', function() {
                    console.log('deleting information');
                    this.close();
                    return true;
                }, function() {
                    this.close();
                    return false;
                })
            .setHeader(header)
            .setting({
                'closable': false, 
                'resizable': true,
                'labels': {'ok': 'Yes', 'cancel': 'No'}
            });
        });
    });
</script>

Upvotes: 0

Views: 1563

Answers (1)

Ngorld
Ngorld

Reputation: 856

Try this simple

$('button').click(function(){
   if(confirm('are you sure?')){
    return alert('Deleted');
   }
   return alert('Not Deleted');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Delete</button>

Upvotes: 1

Related Questions