SweetAlert 2 with 3 buttons

Ahmed15
Tera Contributor

Has anyone been successful with having a sweetalert with more than 2 buttons?

I have download and installed sweetalert2 xml from the store but I still cant get 3 buttons to appear on a alert. I tried the example that’s provided

https://sweetalert.js.org/guides/#advanced-examples but still no luck.  

Example with 3 buttons:

swal("A wild Pikachu appeared! What do you want to do?", {

  buttons: {

    cancel: "Run away!",

    catch: {

      text: "Throw Pokéball!",

      value: "catch",

    },

    defeat: true,

  },

})

.then((value) => {

  switch (value) {

 

    case "defeat":

      swal("Pikachu fainted! You gained 500 XP!");

      break;

 

    case "catch":

      swal("Gotcha!", "Pikachu was caught!", "success");

      break;

 

    default:

      swal("Got away safely!");

  }

});

 

 

Thanks,

 

Ahmed

3 REPLIES 3

Jordan14
Giga Expert

Hey,

 

I got your linked example to work with the following code:

 

In this example, I run the function on click but with an alert it depends on how you want to trigger it, if you share the process I might be able to help further.

I hope this helps.

 

 

HTML:

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>


<div>
<button ng-click="c.open()">please work</button>
</div>

Client Script:

function() {
  /* widget controller */
  var c = this;
	
	
	c.open = function() {
	swal("A wild Pikachu appeared! What do you want to do?", {
  buttons: {
    cancel: "Run away!",
    catch: {
      text: "Throw Pokéball!",
      value: "catch",
    },
    defeat: true,
  },
})
.then((value) => {
  switch (value) {
 
    case "defeat":
      swal("Pikachu fainted! You gained 500 XP!");
      break;
 
    case "catch":
      swal("Gotcha!", "Pikachu was caught!", "success");
      break;
 
    default:
      swal("Got away safely!");
  }
});
	}
	
	
}

 

Result:

find_real_file.png

Ahmed15
Tera Contributor

Thanks for the example.

I wanted to get it work on a client script on the platform view but having no luck.

Did you install  sweetalert2 xml  from the store?

 

No, I just call the .js file in my HTML TEMPLATE. 

 

example:

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

 

Just to confirm, are you trying to get this to work for the Service Portal or something else?