How to ask for confirmation in toastr before deletion
<!DOCTYPE html><html><body>
<p>Example: Click the button to display a confirm box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>function myFunction() { var txt; var r = confirm("Press a button!"); if (r == true) { txt = "You pressed OK!"; } else { txt = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = txt;}</script>
</body></html>
Toastr js add aprove / disaprove button
Sure. You can add any HTML you want to the toast then hook up event handlers to it. See the demo for more details and examples. http://codeseven.github.io/toastr/demo.html
Best confirm dialog JavaScript library
Try jquery-confirm. They have a variety of designs.
Easy way to make a confirmation dialog in Angular?
Method 1
One simple way to confirm is to use the native browser confirm alert.
The template can have a button or link.
<button type=button class="btn btn-primary" (click)="clickMethod('name')">Delete me</button>
And the component method can be something like below.
clickMethod(name: string) {
if(confirm("Are you sure to delete "+name)) {
console.log("Implement delete functionality here");
}
}
Method 2
Another way to get a simple confirmation dialog is to use the angular bootstrap components like ng-bootstrap or ngx-bootstrap. You can simply install the component and use the modal component.
- Examples of modals using ng-bootstrap
- Examples of modals using ngx-bootstrap.
Method 3
Provided below is another way to implement a simple confirmation popup using angular2/material
that I implemented in my project.
app.module.ts
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ConfirmationDialog } from './confirm-dialog/confirmation-dialog';
@NgModule({
imports: [
...
FormsModule,
ReactiveFormsModule
],
declarations: [
...
ConfirmationDialog
],
providers: [ ... ],
bootstrap: [ AppComponent ],
entryComponents: [ConfirmationDialog]
})
export class AppModule { }
confirmation-dialog.ts
import { Component, Input } from '@angular/core';
import { MdDialog, MdDialogRef } from '@angular/material';
@Component({
selector: 'confirm-dialog',
templateUrl: '/app/confirm-dialog/confirmation-dialog.html',
})
export class ConfirmationDialog {
constructor(public dialogRef: MdDialogRef<ConfirmationDialog>) {}
public confirmMessage:string;
}
confirmation-dialog.html
<h1 md-dialog-title>Confirm</h1>
<div md-dialog-content>{{confirmMessage}}</div>
<div md-dialog-actions>
<button md-button style="color: #fff;background-color: #153961;" (click)="dialogRef.close(true)">Confirm</button>
<button md-button (click)="dialogRef.close(false)">Cancel</button>
</div>
app.component.html
<button (click)="openConfirmationDialog()">Delete me</button>
app.component.ts
import { MdDialog, MdDialogRef } from '@angular/material';
import { ConfirmationDialog } from './confirm-dialog/confirmation-dialog';
@Component({
moduleId: module.id,
templateUrl: '/app/app.component.html',
styleUrls: ['/app/main.css']
})
export class AppComponent implements AfterViewInit {
dialogRef: MdDialogRef<ConfirmationDialog>;
constructor(public dialog: MdDialog) {}
openConfirmationDialog() {
this.dialogRef = this.dialog.open(ConfirmationDialog, {
disableClose: false
});
this.dialogRef.componentInstance.confirmMessage = "Are you sure you want to delete?"
this.dialogRef.afterClosed().subscribe(result => {
if(result) {
// do confirmation actions
}
this.dialogRef = null;
});
}
}
index.html => added following stylesheet
<link rel="stylesheet" href="node_modules/@angular/material/core/theming/prebuilt/indigo-pink.css">
Electron app close dialog with message box confirmation
The problem is that you are calling an asynchronous method and the event function continues execution and eventually returns, before any user input is given.
One way to solve this is to use the showMessageBoxSync
function for synchronous operation. This will wait until user selects an option before continuing execution. Like below:
const { dialog } = require('electron');
win.on('close', function (e) {
let response = dialog.showMessageBoxSync(this, {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Are you sure you want to quit?'
});
if(response == 1) e.preventDefault();
});
Related Topics
Show Only a Limited Number of Rows in a Table
How to Toggle (Hide/Show) Sidebar Div Using Jquery
Jquery Wait Until Ajax Call Has Got Data Before Displaying
Disable Click Outside of Bootstrap Modal Area to Close Modal
Typescript Module Has No Exported Members - React
How to Use Owl Carousel Vertically
Get Array of Values from Multiple Inputs Using Jquery
How to Run a Program or Batch File on the Client Side
How to Convert Uint8 Array to Base64 Encoded String
How to Prevent a Key Input from Appearing in Input Field
Angular:How to Implement Condtion Based Click Event
React Router Dom Returns a Blank Page When Going to a Particular Route
Updating Array in Object Properties Using Property'S Name
Javascript Regex Splitting Words in a Comma Separated String
Expand Div on Click With Smooth Animation
How Insert JavaScript into Vue File
Failed to Execute Query Selector on Document, Id Is Not a Valid Selector