forked from sweetalert2/sweetalert2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1552 lines (1450 loc) · 52.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<title>SweetAlert2 - supported fork of t4t5/sweetalert</title>
<link rel="icon" href="./assets/favicon.png">
<link rel="apple-touch-icon" href="./assets/apple-touch-icon.png">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Courgette">
<link rel="stylesheet" href="./assets/example.css">
<link rel="stylesheet" href="./assets/buttons.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/animatecss/3.5.2/animate.css">
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<!-- This is what you need -->
<script src="https://cdn.jsdelivr.net/es6-promise/latest/es6-promise.auto.min.js"></script> <!-- IE support -->
<script src="./dist/sweetalert2.js"></script>
<link rel="stylesheet" href="./dist/sweetalert2.min.css">
<!--.......................-->
</head>
<body>
<header>
<h1>Sweet<span>Alert</span>2</h1>
<h2>A beautiful and customizable replacement for JavaScript's popup boxes</h2>
<h2>Supported fork of t4t5/sweetalert</h2>
<div class="carbonads-wrapper">
<script src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=limontegithubiosweetalert2" id="_carbonads_js" async></script>
</div>
<a class="top-right-button download">Download</a>
<a href="http://www.jsdelivr.com/projects/sweetalert2" class="top-right-button cdn">CDN</a>
<!--form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" class="donate-form">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="8BZF2KUURZ42J">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form-->
</header>
<p>Here’s a comparison of a standard error message. The first one uses the built-in <strong>alert</strong>-function, while the second is using <strong>SweetAlert2</strong>.</p>
<div class="showcase normal">
<h4>Normal alert</h4>
<button>Show error message</button>
<pre><span class="func">alert</span>(<span class="str">'Oops! Something went wrong!'</span>)</pre>
<div class="vs-icon"></div>
</div>
<div class="showcase sweet">
<h4>Sweet<span>Alert</span>2</h4>
<button>Show error message</button>
<pre>
swal(
<span class="str">'Oops...'</span>,
<span class="str">'Something went wrong!'</span>,
<span class="str">'error'</span>
)</pre>
</div>
<p>Pretty cool huh? SweetAlert2 automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. It's even highly customizeable, as you can see below!</p>
<!-- Examples -->
<h3>More examples</h3>
<ul class="examples">
<li class="message">
<div class="ui">
<p>A basic message</p>
<button>Try me!</button>
</div>
<pre>swal(<span class="str">'Any fool can use a computer'</span>)</pre>
</li>
<li class="title-text">
<div class="ui">
<p>A title with a text under</p>
<button>Try me!</button>
</div>
<pre>
swal(
<span class="str">'The Internet?'</span>,
<span class="str">'That thing is still around?'</span>,
<span class="str">'question'</span>
)</pre>
</li>
<li class="success">
<div class="ui">
<p>A success message!</p>
<button>Try me!</button>
</div>
<pre>
swal(
<span class="str">'Good job!'</span>,
<span class="str">'You clicked the button!'</span>,
<span class="str">'success'</span>
)</pre>
</li>
<li class="timer">
<div class="ui">
<p>A message with auto close timer</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Auto close alert!'</span>,
text: <span class="str">'I will close in 2 seconds.'</span>,
timer: <span class="val">2000</span>
}).then(
<span class="func"><i>function</i></span> () {},
<span class="comment">// handling the promise rejection</span>
<span class="func"><i>function</i></span> (dismiss) {
<span class="tag">if</span> (dismiss === <span class="str">'timer'</span>) {
console.log(<span class="str">'I was closed by the timer'</span>)
}
}
)</pre>
</li>
<li class="html">
<div class="ui">
<p>Custom HTML description and buttons</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'<i>HTML</i> <u>example</u>'</span>,
type: <span class="str">'info'</span>,
html:
<span class="str">'You can use <b>bold text</b>, '</span> +
<span class="str">'<a href="//github.com">links</a> '</span> +
<span class="str">'and other HTML tags'</span>,
showCloseButton: <span class="val">true</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonText:
<span class="str">'<i class="fa fa-thumbs-up"></i> Great!'</span>,
cancelButtonText:
<span class="str">'<i class="fa fa-thumbs-down"></i>'</span>
})</pre>
</li>
<li class="html-jquery">
<div class="ui">
<p>jQuery HTML with custom animation (<a href="https://daneden.github.io/animate.css/" target="_blank">Animate.css <i class="fa fa-external-link"></i></a>)</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'jQuery HTML example'</span>,
html: $(<span class="str">'<div>'</span>)
.addClass(<span class="str">'some-class'</span>)
.text(<span class="str">'jQuery is everywhere.'</span>),
animation: <span class="val">false</span>,
customClass: <span class="str">'animated tada'</span>
})</pre>
</li>
<li class="warning confirm">
<div class="ui">
<p>A warning message, with a function attached to the "Confirm"-button...</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Are you sure?'</span>,
text: <span class="str">"You won't be able to revert this!"</span>,
type: <span class="str">'warning'</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonColor: <span class="str">'#3085d6'</span>,
cancelButtonColor: <span class="str">'#d33'</span>,
confirmButtonText: <span class="str">'Yes, delete it!'</span>
}).then(<span class="func"><i>function</i></span> () {
swal(
<span class="str">'Deleted!'</span>,
<span class="str">'Your file has been deleted.'</span>,
<span class="str">'success'</span>
)
})</pre>
</li>
<li class="warning cancel" id="dismiss-handle">
<div class="ui">
<p>... and by passing a parameter, you can execute something else for "Cancel".</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Are you sure?'</span>,
text: <span class="str">"You won't be able to revert this!"</span>,
type: <span class="str">'warning'</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonColor: <span class="str">'#3085d6'</span>,
cancelButtonColor: <span class="str">'#d33'</span>,
confirmButtonText: <span class="str">'Yes, delete it!'</span>,
cancelButtonText: <span class="str">'No, cancel!'</span>,
confirmButtonClass: <span class="str">'btn btn-success'</span>,
cancelButtonClass: <span class="str">'btn btn-danger'</span>,
buttonsStyling: <span class="val">false</span>
}).then(<span class="func"><i>function</i></span> () {
swal(
<span class="str">'Deleted!'</span>,
<span class="str">'Your file has been deleted.'</span>,
<span class="str">'success'</span>
)
}, <span class="func"><i>function</i></span> (dismiss) {
<span class="comment">// dismiss can be 'cancel', 'overlay',</span>
<span class="comment">// 'close', and 'timer'</span>
<span class="tag">if</span> (dismiss === <span class="str">'cancel'</span>) {
swal(
<span class="str">'Cancelled'</span>,
<span class="str">'Your imaginary file is safe :)'</span>,
<span class="str">'error'</span>
)
}
})</pre>
</li>
<li class="custom-image">
<div class="ui">
<p>A message with a custom image and CSS animation disabled</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Sweet!'</span>,
text: <span class="str">'Modal with a custom image.'</span>,
imageUrl: <span class="str">'https://unsplash.it/400/200'</span>,
imageWidth: <span class="val">400</span>,
imageHeight: <span class="val">200</span>,
animation: <span class="val">false</span>
})</pre>
</li>
<li class="custom-width-padding-background">
<div class="ui">
<p>A message with custom width, padding and background</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Custom width, padding, background.'</span>,
width: <span class="val">600</span>,
padding: <span class="val">100</span>,
background: <span class="str">'#fff url(//bit.ly/1Nqn9HU)'</span>
})</pre>
</li>
<li class="ajax-request" id="ajax-request">
<div class="ui">
<p>Ajax request example</p>
<button>Try me!</button>
</div>
<pre>
swal({
title: <span class="str">'Submit email to run ajax request'</span>,
input: <span class="str">'email'</span>,
showCancelButton: <span class="val">true</span>,
confirmButtonText: <span class="str">'Submit'</span>,
showLoaderOnConfirm: <span class="val">true</span>,
preConfirm: <span class="func"><i>function</i></span> (email) {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve, reject) {
<span class="func">setTimeout</span>(<span class="func">function</span>() {
<span class="tag">if</span> (email === <span class="str">'taken@example.com'</span>) {
reject(<span class="str">'This email is already taken.'</span>)
} else {
resolve()
}
}, <span class="val">2000</span>)
})
},
allowOutsideClick: <span class="val">false</span>
}).then(<span class="func"><i>function</i></span> (email) {
swal({
type: <span class="str">'success'</span>,
title: <span class="str">'Ajax request finished!'</span>,
html: <span class="str">'Submitted email: '</span> + email
})
})</pre>
</li>
<li class="chaining-modals" id="chaining-modals">
<div class="ui">
<p>Chaining modals (queue) example</p>
<button>Try me!</button>
</div>
<pre>
swal.setDefaults({
input: <span class="str">'text'</span>,
confirmButtonText: <span class="str">'Next &rarr;'</span>,
showCancelButton: <span class="val">true</span>,
animation: <span class="val">false</span>,
progressSteps: [<span class="str">'1'</span>, <span class="str">'2'</span>, <span class="str">'3'</span>]
})
<span class="func">var</span> steps = [
{
title: <span class="str">'Question 1'</span>,
text: <span class="str">'Chaining swal2 modals is easy'</span>
},
<span class="str">'Question 2'</span>,
<span class="str">'Question 3'</span>
]
swal.queue(steps).then(<span class="func"><i>function</i></span> (result) {
swal.resetDefaults()
swal({
title: <span class="str">'All done!'</span>,
html:
<span class="str">'Your answers: <pre>'</span> +
JSON.stringify(result) +
<span class="str">'</pre>'</span>,
confirmButtonText: <span class="str">'Lovely!'</span>,
showCancelButton: <span class="val">false</span>
})
}, <span class="func"><i>function</i></span> () {
swal.resetDefaults()
})</pre>
</li>
<li class="dynamic-queue" id="dynamic-queue">
<div class="ui">
<p>Dynamic queue example</p>
<button>Try me!</button>
</div>
<pre>
swal.queue([{
title: <span class="str">'Your public IP'</span>,
confirmButtonText: <span class="str">'Show my public IP'</span>,
text:
<span class="str">'Your public IP will be received '</span> +
<span class="str">'via AJAX request'</span>,
showLoaderOnConfirm: <span class="val">true</span>,
preConfirm: <span class="func"><i>function</i></span> () {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve) {
$.get(<span class="str">'https://api.ipify.org?format=json'</span>)
.done(<span class="func"><i>function</i></span> (data) {
swal.insertQueueStep(data.ip)
resolve()
})
})
}
}])</pre>
</li>
</ul>
<!-- Download & Install -->
<h3 class="download-section">Download & install</h3>
<div class="center-container">
<pre class="center">$ bower install sweetalert2</pre>
<p>Or</p>
<pre class="center">$ npm install sweetalert2</pre>
<p>
Or download from CDN:
<a href="https://www.jsdelivr.com/projects/sweetalert2" target="_blank">jsdelivr.com/sweetalert2 <i class="fa fa-external-link"></i></a>
<span class="mobile-hidden"> | </span>
<a href="https://cdnjs.com/libraries/limonte-sweetalert2" target="_blank">cdnjs.com/limonte-sweetalert2 <i class="fa fa-external-link"></i></a>
</p>
</div>
<ol>
<li>
<p>Initialize the plugin by referencing the necessary files:</p>
<pre><span class="comment"><!-- for IE support --></span>
<<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"bower_components/es6-promise/es6-promise.auto.min.js"</span>></<span class="tag">script</span>>
<<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"bower_components/sweetalert2/dist/sweetalert2.min.js"</span>></<span class="tag">script</span>>
<<span class="tag">link</span> <span class="attr">rel</span>=<span class="str">"stylesheet"</span> <span class="tag">href</span>=<span class="str">"bower_components/sweetalert2/dist/sweetalert2.min.css"</span>></pre>
<p>Or</p>
<pre><span class="comment">// ES6 Modules</span>
<span class="val">import</span> { default as swal } <span class="val">from</span> <span class="str">'sweetalert2'</span>
<span class="comment">// CommonJS</span>
<span class="val">const</span> swal = <span class="func">require</span>(<span class="str">'sweetalert2'</span>)</pre>
</li>
<li>
<p>Call the sweetAlert2-function after the page has loaded</p>
<pre>
swal({
title: <span class="str">'Error!'</span>,
text: <span class="str">'Do you want to continue'</span>,
type: <span class="str">'error'</span>,
confirmButtonText: <span class="str">'Cool'</span>
})</pre>
</li>
</ol>
<div class="mobile-hidden">
<!-- Configuration -->
<h3>Configuration</h3>
<p class="center">Here are the keys that you can use if you pass an object into sweetAlert2:</p>
<table>
<tr class="titles">
<th>
Argument
</th>
<th>Default value</th>
<th>
Description
</th>
</tr>
<tr>
<td><b>title</b></td>
<td><i>null</i></td>
<td>The title of the modal, as HTML. It can either be added to the object under the key "title" or passed as the first parameter of the function.</td>
</tr>
<tr>
<td><b>titleText</b></td>
<td><i>null</i></td>
<td>The title of the modal, as text. Useful to avoid HTML injection.</td>
</tr>
<tr>
<td><b>text</b></td>
<td><i>null</i></td>
<td>A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function.</td>
</tr>
<tr>
<td><b>html</b></td>
<td><i>null</i></td>
<td>A HTML description for the modal. If "text" and "html" parameters are provided in the same time, "text" will be used.</td>
</tr>
<tr>
<td><b>type</b></td>
<td><i>null</i></td>
<td>The type of the modal. SweetAlert2 comes with 5 built-in types which will show a corresponding icon animation: <strong>warning</strong>, <strong>error</strong>, <strong>success</strong>, <strong>info</strong> and <strong>question</strong>. It can either be put in the array under the key "type" or passed as the third parameter of the function.</td>
</tr>
<tr id="input-parameter">
<td><b>input</b></td>
<td><i>null</i></td>
<td>
Input field type, can be
<strong>text</strong>, <strong>email</strong>, <strong>password</strong>,
<strong>number</strong>, <strong>tel</strong>, <strong>range</strong>,
<strong>textarea</strong>, <strong>select</strong>, <strong>radio</strong>,
<strong>checkbox</strong> and <strong>file</strong>.
</td>
</tr>
<tr>
<td><b>width</b></td>
<td><i>'500px'</i></td>
<td>Modal window width, including paddings (<i>box-sizing: border-box</i>). Can be in <strong>px</strong> or <strong>%</strong>.</td>
</tr>
<tr>
<td><b>padding</b></td>
<td><i>20</i></td>
<td>Modal window padding.</td>
</tr>
<tr>
<td><b>background</b></td>
<td><i>'#fff'</i></td>
<td>Modal window background (CSS background property).</td>
</tr>
<tr>
<td><b>customClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the modal.</td>
</tr>
<tr id="timer">
<td><b>timer</b></td>
<td><i>null</i></td>
<td>Auto close timer of the modal. Set in ms (milliseconds).</td>
</tr>
<tr>
<td><b>animation</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, modal CSS animation will be disabled.</td>
</tr>
<tr id="allow-outside-click">
<td><b>allowOutsideClick</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, the user can't dismiss the modal by clicking outside it.</td>
</tr>
<tr id="allow-escape-key">
<td><b>allowEscapeKey</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, the user can't dismiss the modal by pressing the Escape key.</td>
</tr>
<tr>
<td><b>showConfirmButton</b></td>
<td><i>true</i></td>
<td>If set to <strong>false</strong>, a "Confirm"-button will not be shown. It can be useful when you're using custom HTML description.</td>
</tr>
<tr id="show-cancel-button">
<td><b>showCancelButton</b></td>
<td><i>false</i></td>
<td>If set to <strong>true</strong>, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.</td>
</tr>
<tr>
<td><b>confirmButtonText</b></td>
<td><i>'OK'</i></td>
<td>Use this to change the text on the "Confirm"-button.</td>
</tr>
<tr>
<td><b>cancelButtonText</b></td>
<td><i>'Cancel'</i></td>
<td>Use this to change the text on the "Cancel"-button.</td>
</tr>
<tr>
<td><b>confirmButtonColor</b></td>
<td><i>'#3085d6'</i></td>
<td>Use this to change the background color of the "Confirm"-button (must be a HEX value).</td>
</tr>
<tr>
<td><b>cancelButtonColor</b></td>
<td><i>'#aaa'</i></td>
<td>Use this to change the background color of the "Cancel"-button (must be a HEX value).</td>
</tr>
<tr>
<td><b>confirmButtonClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the "Confirm"-button.</td>
</tr>
<tr>
<td><b>cancelButtonClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the "Cancel"-button.</td>
</tr>
<tr>
<td><b>buttonsStyling</b></td>
<td><i>true</i></td>
<td>Apply default swal2 styling to buttons. If you want to use your own classes (e.g. Bootstrap classes) set this parameter to <strong>false</strong>.</td>
</tr>
<tr>
<td><b>reverseButtons</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> if you want to invert default buttons positions.</td>
</tr>
<tr>
<td><b>focusCancel</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> if you want to focus the "Cancel"-button by default.</td>
</tr>
<tr id="show-close-button">
<td><b>showCloseButton</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> to show close button in top right corner of the modal.</td>
</tr>
<tr>
<td><b>showLoaderOnConfirm</b></td>
<td><i>false</i></td>
<td>Set to <strong>true</strong> to disable buttons and show that something is loading. Useful for AJAX requests.</td>
</tr>
<tr>
<td><b>preConfirm</b></td>
<td><i>null</i></td>
<td>Function to execute before confirm, should return Promise, see <a href="#ajax-request">usage example</a>.</td>
</tr>
<tr id="image">
<td><b>imageUrl</b></td>
<td><i>null</i></td>
<td>Add a customized icon for the modal. Should contain a string with the path or URL to the image.</td>
</tr>
<tr>
<td><b>imageWidth</b></td>
<td><i>null</i></td>
<td>If imageUrl is set, you can specify imageWidth to describes image width in px.</td>
</tr>
<tr>
<td><b>imageHeight</b></td>
<td><i>null</i></td>
<td>Custom image height in px.</td>
</tr>
<tr>
<td><b>imageClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the customized icon.</td>
</tr>
<tr id="input-placeholder">
<td><b>inputPlaceholder</b></td>
<td><i>''</i></td>
<td>Input field placeholder.</td>
</tr>
<tr id="input-value">
<td><b>inputValue</b></td>
<td><i>''</i></td>
<td>Input field initial value.</td>
</tr>
<tr id="input-options">
<td><b>inputOptions</b></td>
<td><i>{} or Promise</i></td>
<td>If <strong>input</strong> parameter is set to <strong>"select"</strong> or <strong>"radio"</strong>, you can provide options. Object keys will represent options values, object values will represent options text values.</td>
</tr>
<tr id="input-auto-trim">
<td><b>inputAutoTrim</b></td>
<td><i>true</i></td>
<td>Automatically remove whitespaces from both ends of a result string. Set this parameter to <strong>false</strong> to disable auto-trimming.</td>
</tr>
<tr id="input-validator">
<td><b>inputValidator</b></td>
<td><i>null</i></td>
<td>Validator for input field, should return Promise, see <a href="#select-box">usage example</a>.</td>
</tr>
<tr id="input-class">
<td><b>inputClass</b></td>
<td><i>null</i></td>
<td>A custom CSS class for the input field.</td>
</tr>
<tr>
<td><b>progressSteps</b></td>
<td><i>[]</i></td>
<td>Progress steps, useful for modal queues, see <a href="#chaining-modals">usage example</a>.</td>
</tr>
<tr>
<td><b>currentProgressStep</b></td>
<td><i>null</i></td>
<td>Current active progress step. The default is <strong>swal.getQueueStep()</strong></td>
</tr>
<tr>
<td><b>progressStepsDistance</b></td>
<td><i>'40px'</i></td>
<td>Distance between progress steps.</td>
</tr>
<tr>
<td><b>onOpen</b></td>
<td><i>null</i></td>
<td>Function to run when modal opens, provides modal DOM element as the first argument.</td>
</tr>
<tr>
<td><b>onClose</b></td>
<td><i>null</i></td>
<td>Function to run when modal closes, provides modal DOM element as the first argument.</td>
</tr>
</table>
<p class="center">
You can redefine default params by using <strong>swal.setDefaults(customParams)</strong>.
</p>
</div>
<!-- Handling Dismissals -->
<div class="center-container">
<h3>Handling Dismissals</h3>
<p class="center">When an alert is dismissed by the user, the Promise returned by <strong>swal()</strong> will reject with a string documenting the reason it was dismissed:</p>
<table>
<tr class="titles">
<th>String</th>
<th>Description</th>
<th>Related configuration</th>
</tr>
<tr>
<td><strong>'overlay'</strong></td>
<td>The user clicked the overlay.</td>
<td><a href="#allow-outside-click">allowOutsideClick</a></td>
</tr>
<tr>
<td><strong>'cancel'</strong></td>
<td>The user clicked the cancel button.</td>
<td><a href="#show-cancel-button">showCancelButton</a></td>
</tr>
<tr>
<td><strong>'close'</strong></td>
<td>The user clicked the close button.</td>
<td><a href="#show-close-button">showCloseButton</a></td>
</tr>
<tr>
<td><strong>'esc'</strong></td>
<td>The user clicked the Esc key.</td>
<td><a href="#allow-escape-key">allowEscapeKey</a></td>
</tr>
<tr>
<td><strong>'timer'</strong></td>
<td>The timer ran out, and the alert closed automatically.</td>
<td><a href="#timer">timer</a></td>
</tr>
</table>
<p class="center">
If rejections are not handled, it will be logged as an error.
To avoid this, add a rejection handler to the Promise.<br>
Alternatively, you can use <strong>.catch(swal.noop)</strong> as a quick way to simply suppress the errors:
</p>
<pre>
swal('...')
.catch(swal.noop)</pre>
</div>
<!-- Modal Types -->
<h3>Modal Types</h3>
<table class="modal-types">
<tr>
<td><strong>success</strong></td>
<td><div class="swal2-icon swal2-success"> <span class="line tip animate-success-tip"></span> <span class="line long animate-success-long"></span> <div class="placeholder"></div></div></td>
<td><button class="type-success">Try me!</button></td>
</tr>
<tr>
<td><strong>error</strong></td>
<td><div class="swal2-icon swal2-error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div></td>
<td><button class="type-error">Try me!</button></td>
</tr>
<tr>
<td><strong>warning</strong></td>
<td><div class="swal2-icon swal2-warning">!</div></td>
<td><button class="type-warning">Try me!</button></td>
</tr>
<tr>
<td><strong>info</strong></td>
<td><div class="swal2-icon swal2-info">i</div></td>
<td><button class="type-info">Try me!</button></td>
</tr>
<tr>
<td><strong>question</strong></td>
<td><div class="swal2-icon swal2-question">?</div></td>
<td><button class="type-question">Try me!</button></td>
</tr>
</table>
<!-- Input Types -->
<h3>Input Types</h3>
<table class="modal-input-types">
<tr id="input-field">
<td><strong>text</strong></td>
<td>
<pre>
swal({
title: <span class="str">'Input something'</span>,
input: <span class="str">'text'</span>,
showCancelButton: <span class="val">true</span>,
inputValidator: <span class="func"><i>function</i></span> (value) {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve, reject) {
<span class="tag">if</span> (value) {
resolve()
} <span class="tag">else</span> {
reject(<span class="str">'You need to write something!'</span>)
}
})
}
}).then(<span class="func"><i>function</i></span> (result) {
swal({
type: <span class="str">'success'</span>,
html: <span class="str">'You entered: '</span> + result
})
})</pre>
</td>
<td><button class="input-type-text">Try me!</button></td>
</tr>
<tr id="input-email">
<td><strong>email</strong></td>
<td>
<pre>
swal({
title: <span class="str">'Input email address'</span>,
input: <span class="str">'email'</span>
}).then(<span class="func"><i>function</i></span> (email) {
swal({
type: <span class="str">'success'</span>,
html: <span class="str">'Entered email: '</span> + email
})
})</pre>
</td>
<td><button class="input-type-email">Try me!</button></td>
</tr>
<tr id="input-password">
<td><strong>password</strong></td>
<td>
<pre>
swal({
title: <span class="str">'Enter your password'</span>,
input: <span class="str">'password'</span>,
inputAttributes: {
<span class="str">'maxlength'</span>: <span class="val">10</span>,
<span class="str">'autocapitalize'</span>: <span class="str">'off'</span>,
<span class="str">'autocorrect'</span>: <span class="str">'off'</span>
}
}).then(<span class="func"><i>function</i></span> (password) {
<span class="tag">if</span> (password) {
swal({
type: <span class="str">'success'</span>,
html: <span class="str">'Entered password: '</span> + password
})
}
})</pre>
</td>
<td><button class="input-type-password">Try me!</button></td>
</tr>
<tr id="input-textarea">
<td><strong>textarea</strong></td>
<td>
<pre>
swal({
input: <span class="str">'textarea'</span>,
showCancelButton: <span class="val">true</span>
}).then(<span class="func"><i>function</i></span> (text) {
<span class="tag">if</span> (text) {
swal(text)
}
})</pre>
</td>
<td><button class="input-type-textarea">Try me!</button></td>
</tr>
<tr id="select-box">
<td><strong>select</strong></td>
<td>
<pre>
swal({
title: <span class="str">'Select Ukraine'</span>,
input: <span class="str">'select'</span>,
inputOptions: {
<span class="str">'SRB'</span>: <span class="str">'Serbia'</span>,
<span class="str">'UKR'</span>: <span class="str">'Ukraine'</span>,
<span class="str">'HRV'</span>: <span class="str">'Croatia'</span>
},
inputPlaceholder: <span class="str">'Select country'</span>,
showCancelButton: <span class="val">true</span>,
inputValidator: <span class="func"><i>function</i></span> (value) {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve, reject) {
<span class="tag">if</span> (value === <span class="str">'UKR'</span>) {
resolve()
} <span class="tag">else</span> {
reject(<span class="str">'You need to select Ukraine :)'</span>)
}
})
}
}).then(<span class="func"><i>function</i></span> (result) {
swal({
type: <span class="str">'success'</span>,
html: <span class="str">'You selected: '</span> + result
})
})</pre>
</td>
<td><button class="input-type-select">Try me!</button></td>
</tr>
<tr id="radio-inputs">
<td><strong>radio</strong></td>
<td>
<pre>
<span class="comment">// inputOptions can be an object or Promise</span>
<span class="func">var</span> inputOptions = <span class="tag">new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve) {
setTimeout(<span class="func"><i>function</i></span> () {
resolve({
<span class="str">'#ff0000'</span>: <span class="str">'Red'</span>,
<span class="str">'#00ff00'</span>: <span class="str">'Green'</span>,
<span class="str">'#0000ff'</span>: <span class="str">'Blue'</span>
})
}, <span class="val">2000</span>)
})
swal({
title: <span class="str">'Select color'</span>,
input: <span class="str">'radio'</span>,
inputOptions: inputOptions,
inputValidator: <span class="func"><i>function</i></span> (result) {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve, reject) {
<span class="tag">if</span> (result) {
resolve()
} <span class="tag">else</span> {
reject(<span class="str">'You need to select something!'</span>)
}
})
}
}).then(<span class="func"><i>function</i></span> (result) {
swal({
type: <span class="str">'success'</span>,
html: <span class="str">'You selected: '</span> + result
})
})</pre>
</td>
<td><button class="input-type-radio">Try me!</button></td>
</tr>
<tr id="checkbox">
<td><strong>checkbox</strong></td>
<td>
<pre>
swal({
title: <span class="str">'Terms and conditions'</span>,
input: <span class="str">'checkbox'</span>,
inputValue: <span class="val">1</span>,
inputPlaceholder:
<span class="str">'I agree with the terms and conditions'</span>,
confirmButtonText:
<span class="str">'Continue <i class="fa fa-arrow-right></i>'</span>,
inputValidator: <span class="func"><i>function</i></span> (result) {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve, reject) {
<span class="tag">if</span> (result) {
resolve()
} <span class="tag">else</span> {
reject(<span class="str">'You need to agree with T&C'</span>)
}
})
}
}).then(<span class="func"><i>function</i></span> (result) {
swal({
type: <span class="str">'success'</span>,
text: <span class="str">'You agreed with T&C :)'</span>
})
})</pre>
</td>
<td><button class="input-type-checkbox">Try me!</button></td>
</tr>
<tr id="input-file">
<td><strong>file</strong></td>
<td>
<pre>
swal({
title: <span class="str">'Select image',</span>
input: <span class="str">'file',</span>
inputAttributes: {
accept: <span class="str">'image/*'</span>
}
}).then(<span class="func"><i>function</i></span> (file) {
<span class="func">var</span> reader = <span class="tag">new</span> <span class="func">FileReader</span>
reader.onload = <span class="func"><i>function</i></span> (e) {
swal({
imageUrl: e.target.result
})
}
reader.readAsDataURL(file)
})</pre>
</td>
<td><button class="input-type-file">Try me!</button></td>
</tr>
<tr id="input-range">
<td><strong>range</strong></td>
<td>
<pre>
swal({
title: <span class="str">'How old are you?',</span>
type: <span class="str">'question',</span>
input: <span class="str">'range',</span>
inputAttributes: {
min: <span class="val">8</span>,
max: <span class="val">120</span>,
step: <span class="val">1</span>
},
inputValue: <span class="val">25</span>
})</pre>
</td>
<td><button class="input-type-range">Try me!</button></td>
</tr>
</table>
<div class="mobile-hidden">
<p>
Multiple inputs aren't supported, you can achieve them by using <strong>html</strong> and <strong>preConfirm</strong> parameters.<br>
Inside the <strong>preConfirm()</strong> function you can pass the custom result to the <strong>resolve()</strong> function as a parameter:
</p>
<table class="modal-input-types">
<tr id="multiple-inputs">
<td></td>
<td>
<pre>
swal({
title: <span class="str">'Multiple inputs'</span>,
html:
<span class="str">'<input id="swal-input1" class="swal2-input" autofocus>'</span> +
<span class="str">'<input id="swal-input2" class="swal2-input">'</span>,
preConfirm: <span class="func"><i>function</i></span> () {
<span class="tag">return new</span> <span class="func">Promise</span>(<span class="func"><i>function</i></span> (resolve) {
resolve([
$(<span class="str">'#swal-input1'</span>).val(),
$(<span class="str">'#swal-input2'</span>).val()
])
})
}
}).then(<span class="func"><i>function</i></span> (result) {
swal(JSON.stringify(result))
}).catch(swal.noop)</pre>
</td>
<td><button class="input-type-multiple">Try me!</button></td>
</tr>
</table>
<!-- Methods -->
<h3>Methods</h3>
<table>
<tr class="titles">
<th>
Method
</th>