The CreatorCon Call for Content is officially open! Get started here.

SweetAlert - a beautiful replacement for javascript's "alert"

Matt Saxton - G
Kilo Guru

 

SweetAlerts2 is out. 

 

SweetAlerts2

 

Hi Dev's,

 

Last night i was working on an application that needed some input. So i used SweetAlerts on the custom UI page and it turned out really nice looking, and i thought i could use globally!.

 

ServiceNow Share - SweetAlert

 

Once you install you can do any of the tests via the console

 

parent.swal({     title: "Are you sure?",     text: "You will not be able to recover this imaginary file!",     type: "warning",     showCancelButton: true,     confirmButtonColor: "#DD6B55",     confirmButtonText: "Yes, delete it!",     closeOnConfirm: false }, function(){     swal("Deleted!", "Your imaginary file has been deleted.", "success"); });

 

Make sure that you use "parent.swal()"

 

Here's more examples listed here SweetAlert

 

Screenshot's below.

 

2015-10-01 13_48_38-ServiceNow.png

 

2015-10-01 13_37_06-ServiceNow.png

44 REPLIES 44

Hi Venkat,

I tried the swal alert for onsubmit function. It pops up the alert, but it stays only for few seconds and submits the form even-though 'OK' is not clicked. Do you have any idea on this?

Thanks,

Sindhu.

Hello Sindhu

Sorry for delayed response. Nope I did not come across this issue, the box remains on the form unless you hit OK. Did you set any kind of timer?

Let me look at it meanwhile.

Regards!

elemonnier
Tera Expert

Do you have an example of using SweetAlerts2 in a client script where you could process the result answer. The examples from SweetAlerts2 use  .then((result) => {} which don't seem to work in SN. 

swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.value) {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})

kevinray
Giga Expert

hi. Cant seem to make your last example work. Can we see your code for the "Are you sure" option? The example in SweetAlert doesn't work because you can't use => per the example in SweetAlert, and the code you put in your post:

 

parent.swal({     title: "Are you sure?",     text: "You will not be able to recover this imaginary file!",     type: "warning",     showCancelButton: true,     confirmButtonColor: "#DD6B55",     confirmButtonText: "Yes, delete it!",     closeOnConfirm: false }, function(){     swal("Deleted!", "Your imaginary file has been deleted.", "success"); });

 

Does not work, nor does it match your screen shot.

 

Can we just see your code. That would be so helpful! Thank you.

elemonnier
Tera Expert

That example was from the SweetAlerts2 page. I'm looking for an example of a yes,no alert with a response. It seems when you call swal, it continues with javascript execution instead of waiting for a response.

Do you have an example of where you ask a question and then process the response?

Thanks