10 examples of 'alert with ok and cancel' in JavaScript

Every line of 'alert with ok and cancel' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
24onCLickOk() {
25 Navigation.dismissOverlay(this.props.componentId);
26}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

29function alertOk(msg, callback){
30 swal({
31 title:"提示信息",
32 text: msg,
33 type:"success",
34 timer: 3000
35 }, callback);
36}
263async function alert(title, ...msgs) {
264 return createDialog({title, msgs});
265}
111static alert(
112 title: ?string,
113 message?: ?string,
114 buttons?: Buttons,
115): void {
116 var config = {
117 title: title || '',
118 message: message || '',
119 };
120 // At most three buttons (neutral, negative, positive). Ignore rest.
121 // The text 'OK' should be probably localized. iOS Alert does that in native.
122 var validButtons: Buttons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
123 var buttonPositive = validButtons.pop();
124 var buttonNegative = validButtons.pop();
125 var buttonNeutral = validButtons.pop();
126 if (buttonNeutral) {
127 config = {...config, buttonNeutral: buttonNeutral.text || '' }
128 }
129 if (buttonNegative) {
130 config = {...config, buttonNegative: buttonNegative.text || '' }
131 }
132 if (buttonPositive) {
133 config = {...config, buttonPositive: buttonPositive.text || '' }
134 }
135 DialogModuleAndroid.showAlert(
136 config,
137 (errorMessage) => console.warn(message),
138 (action, buttonKey) => {
139 if (action !== DialogModuleAndroid.buttonClicked) {
140 return;
141 }
142 if (buttonKey === DialogModuleAndroid.buttonNeutral) {
143 buttonNeutral.onPress && buttonNeutral.onPress();
144 } else if (buttonKey === DialogModuleAndroid.buttonNegative) {
145 buttonNegative.onPress && buttonNegative.onPress();
146 } else if (buttonKey === DialogModuleAndroid.buttonPositive) {
147 buttonPositive.onPress && buttonPositive.onPress();
148 }
149 }
150 );
151}
39async function okIfAlert (driver) {
40 let text;
41 try {
42 text = await driver.getAlertText();
43 } catch (err) {
44 // if NoAlertOpenError (27) continue
45 if (err.jsonwpCode !== 27) {
46 throw err;
47 }
48 }
49 if (text) {
50 await driver.postAcceptAlert();
51 }
52}
50ok(): void {
51 if (this.selectedSymbol == null) {
52 this.dismiss();
53 } else {
54 this.close({$value: this.selectedSymbol});
55 }
56}
114alert(title, duration = '') {
115 duration = duration || this.configure.duration
116 wx.showToast({
117 title,
118 image: this.configure.alertIconPath,
119 mask: true,
120 duration
121 })
122
123 return new Promise((resolve, reject) => {
124 setTimeout(() => {
125 resolve()
126 }, duration)
127 })
128}
17doAlert() {
18 const alert = this.alertCtrl.create({
19 title: 'New Friend!',
20 subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
21 buttons: ['Ok']
22 });
23
24 alert.present();
25}
122alert(options: any = {}, successCb = noop, closeCb = noop) {
123 const defaultOptions: any = {
124 type: options.type || null,
125 title: options.title || null,
126 text: options.text || null,
127 buttonsStyling: options.buttonsStyling || false,
128 confirmButtonClass: options.confirmButtonClass || 'btn btn-lg btn-secondary',
129 animation: options.animation || true,
130 customClass: options.customClass || '',
131 }
132
133 if (closeCb !== noop) {
134 defaultOptions.showCancelButton = options.showCancelButton || true
135 defaultOptions.cancelButtonClass = options.cancelButtonClass || 'btn btn-lg btn-secondary'
136 }
137
138 return swal(assign(defaultOptions, options))
139 .then(res => successCb(res), dismiss => closeCb(dismiss))
140}
17ok(): void {
18 this.$close(true);
19 this.setDialogMessage('');
20}

Related snippets