t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.39k stars 2.84k forks source link

"icon:" not working #873

Closed Badetuch closed 5 years ago

Badetuch commented 5 years ago

Hello,

Here is my code: https://hastebin.com/qusumeyino.js

When i click "verbinden" i wanna see the "succes" icon, how do i set it up? I tried it so: https://hastebin.com/ezozirogin.coffeescript And I want that when i click "verbinden" that a internet page opens.

Im realy sorry for my bad English. Hope sb can help my

Greetings from Germany :)

lionralfs commented 5 years ago

Hey @Badetuch,

you need to pass the options to the second swal() as well:

document.getElementById("alert").addEventListener("click", function() {
  swal({
    title: "Info",
    text: "Mit dem verbinden akzeptierst du automatisch die geltenen Regel unseres Teamspeaks!",
    icon: "warning",
    buttons: {
      cancel: "Abbrechen",
      senden: {
        text: "Verbinden",
        value: "verbinden"
      }
    }
  }).then(value => {
    switch (value) {
      case "verbinden":
        swal("Erfolgreich verbunden", {
          icon: "success"
        }).then(() => {
          location.href = "https://google.com";
        });
        break;
    }
  });
});
Badetuch commented 5 years ago

Thank your so much dude. But how can i make, when i click "verbinden" that i get to another page not when i press "verbinden" and "Ok" after.

Hope u understand me :(

lionralfs commented 5 years ago

If you redirected to another page, as soon as you click "verbinden", you would never see the 2nd alert. If that's what you want, you could use this:

document.getElementById("alert").addEventListener("click", function() {
  swal({
    title: "Info",
    text:
      "Mit dem verbinden akzeptierst du automatisch die geltenen Regel unseres Teamspeaks!",
    icon: "warning",
    buttons: {
      cancel: "Abbrechen",
      senden: {
        text: "Verbinden",
        value: "verbinden"
      }
    }
  }).then(value => {
    switch (value) {
      case "verbinden":
          location.href = "https://google.com";
        break;
    }
  });
});

Alternatively, you redirect after a short timeout (1 second in this case) while showing the 2nd alert:

document.getElementById("alert").addEventListener("click", function() {
  swal({
    title: "Info",
    text:
      "Mit dem verbinden akzeptierst du automatisch die geltenen Regel unseres Teamspeaks!",
    icon: "warning",
    buttons: {
      cancel: "Abbrechen",
      senden: {
        text: "Verbinden",
        value: "verbinden"
      }
    }
  }).then(value => {
    switch (value) {
      case "verbinden":
        setTimeout(() => {
          location.href = "https://google.com";
        }, 1000);
        swal("Erfolgreich verbunden", {
          icon: "success"
        });
        break;
    }
  });
});
Badetuch commented 5 years ago

Thanks sooooo much dude u helped my realy much. If u want i have another question opend: https://github.com/t4t5/sweetalert/issues/874

Greetings from Germany :)

lionralfs commented 5 years ago

Glad I could help