Not removing “OK” button from sweet alert dialog

Viewed 3331

As i'm using sweet alert in my project so i'm trying to change button text and add cancel button. In some pages it works but in some it fails and only shows OK fixed, here is my screenshot below.
working

Its working as seen with Yes and Cancel button but in other page it shows as follows.

not working

Here is my code which i'm using below.

function DeleteSubscription(CompanySubscriptionId, CompanyId) {
            swal({
                title: "Are you sure?",
                text: ("You want to delete this Subscription !"),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#5cb85c",
                confirmButtonText: "Yes",
                closeOnConfirm: false
            })
                .then(function (isConfirm) {
                    if (isConfirm) {
                        
                            }
                        });
                    }
                });
        }

As on the second image its not showing button as Yes and Cancel only OK.

2 Answers

I added fire into Swal, and ran it - Seems like that works fine - It had errors before though - But you have to many closing brackets in your function as well -

Don't you have any console errors?

Using SweetAlert 2

Swal.fire({
                title: "Are you sure?",
                text: ("You want to delete this Subscription !"),
                //type: "warning", -  doesn't exist
                showCancelButton: true,
                 confirmButtonColor: '#d33',
                confirmButtonText: "Yes",
                //closeOnConfirm: false -  doesn't exist
            })
                .then(function (isConfirm) {
                    if (isConfirm) {
                        
                            }
                        });
                    
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9.17.1/dist/sweetalert2.all.min.js"></script>

Using SweetAlert 1, I added comments explaining what is happening

swal({
                    title: "Are you sure?",
                    text: ("You want to delete this Subscription !"),
                    type: "warning", //type and imageUrl have been replaced with a single icon option.
                    icon:'warning', //The right way
                    showCancelButton: true, //showCancelButton and showConfirmButton are no longer needed. Instead, you can set buttons: true to show both buttons, or buttons: false to hide all buttons. By default, only the confirm button is shown.
                    confirmButtonColor: '#d33', //you should specify all stylistic changes through CSS. As a useful shorthand, you can set dangerMode: true to make the confirm button red. Otherwise, you can specify a class in the button object.
                    confirmButtonText: "Yes", // everything is in the buttons argument now
                    closeOnConfirm: false,
                    buttons:true,//The right way
                    buttons: ["No", "Yes"] //The right way to do it in Swal1
                })
                    .then(function (isConfirm) {
                        if (isConfirm) {
                            
                                }
                            });
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

Seems like you missing some parameter, check the doc: https://sweetalert2.github.io/#examples

Swal.fire({
    title: "Are you sure?",
    text: ("You want to delete this Subscription !"),
    //type: "warning", -  doesn't exist
    showCancelButton: true,
     showCloseButton: true, // optional
     showConfirmButton: true, // optional
    confirmButtonColor: '#d33',
    confirmButtonText: "Yes",
    //closeOnConfirm: false -  doesn't exist
  })
  .then(function(isConfirm) {
    if (isConfirm) {

    }
  });
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9.17.1/dist/sweetalert2.all.min.js"></script>

Related