Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a confirmation alert for delete button in Angular using JS

Tags:

I have a form that has a delete button, I would like to create a confirmation box that pop ups when the delete button is clicked. The delete button currently works. I have tried several things in javascript with no luck. I am using Angular.

Is this best approach for this?

Also, does anyone know of any examples for this, I have not found any that work.

$(document).ready(function(){
  $("form").validate();
  $(".radius small success button").ConfirmDialog('Are you sure?');
});
like image 758
FluxEngine Avatar asked Mar 14 '13 21:03

FluxEngine


People also ask

How do I delete with confirmation?

On the desktop, navigate to the "Recycle Bin" folder. Right-click on the Recycle Bin folder and click on the "Properties" option. "Recycle Bin Properties" window will appear on the screen. Click (select) on the "Display delete confirmation dialog" option and click on the "Apply" button to proceed.

Are you sure you want to delete in JavaScript?

Use Window confirm() method in the client-side to confirm delete before delete in JavaScript. When you want to verify the user or delete something, it always a good idea to confirm the request before processing. The confirm() method show a dialog box with a message and two buttons (OK and Cancel).

How do you get the confirmation message box in angular 6?

One simple way to confirm is to use the native browser confirm alert. The template can have a button or link. And the component method can be something like below. Another way to get a simple confirmation dialog is to use the angular bootstrap components like ng-bootstrap or ngx-bootstrap.


1 Answers

Seems like an AngularJS directive is a bit over-the-top for a solution to this. Seems easier just to use straight javascript unless you need some custom functionality to your "confirm()" function.

if (confirm('Are you sure you want to delete this?')) {
     // TODO:  Do something here if the answer is "Ok".
}

Hope this helps, cheers

UPDATE: Actually, with Angular, it would be better to use $window.confirm as this would allow you to test with Karma/Jasmine.

like image 164
Steven Rogers Avatar answered Sep 16 '22 15:09

Steven Rogers