32

I am using javascript sweetalert2 library.

I want to remove the OK button from the alert box but I did not find any property for not to display this button.

I am using the timer property timer:1000 for closing the alert in one second. So, I don't think there is a use of the ok button in this matter.

enter image description here

Penny Liu
  • 7,720
  • 5
  • 40
  • 66
Ankush Rishi
  • 2,362
  • 7
  • 21
  • 53

10 Answers10

52

You can use these properties:

showCancelButton: false, // There won't be any cancel button
showConfirmButton: false // There won't be any confirm button

Like This

swal({
  title: 'Auto close alert!',
  text: 'I will close in 2 seconds.',
  timer: 2000,
  showCancelButton: false,
  showConfirmButton: false
}).then(
  function () {},
  // handling the promise rejection
  function (dismiss) {
    if (dismiss === 'timer') {
      //console.log('I was closed by the timer')
    }
  }
)
Player1
  • 1,561
  • 18
  • 31
Viplock
  • 2,976
  • 22
  • 30
22

Update 4/6/2018

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.

So now instead of doing

showCancelButton: false;

showConfirmButton: false;

Just do

buttons: false;

Guides

NewBie
  • 1,334
  • 7
  • 15
5

You need to set showConfirmButton:false in your configuration.

swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showConfirmButton:false,
  confirmButtonText: 'Yes, delete it!'
})

Here's the fiddle

Saurabh Sharma
  • 2,364
  • 4
  • 18
  • 36
3

This works for me: $(".confirm").attr('disabled', 'disabled');

My function:

function DeleteConfirm(c){
  swal({   
            title: "Want to delete this item?",   
            text: "You will not be able to undo this action!",   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonColor: "#DD6B55",   
            confirmButtonText: "Yes, delete it!",   
            closeOnConfirm: false 
        }, function(){ 
          $(".confirm").attr('disabled', 'disabled'); 

        });
}
toonarmycaptain
  • 1,531
  • 1
  • 14
  • 26
Salah
  • 31
  • 2
2
swal({

    title: "Success",
    text: "Permissions assigned Successfully",
    icon: "success",
    closeOnClickOutside: false,
})

Use closeOnClickOutside: false, It works for me.

Saurabh Sharma
  • 2,364
  • 4
  • 18
  • 36
2

This accepted answer has been deprecated. Here is how you can hide or remove buttons in SweetAlert2.

{
  buttons: false,
}
kaleazy
  • 4,966
  • 2
  • 40
  • 47
0

Try setting the showConfirmButton property to false.

Look at their docs

the_lost_one
  • 127
  • 9
0

Below code works for me

I have only set buttons: false;

and update

swal({
    title: 'Auto close alert!',
    text: 'I will close in 2 seconds.',
    timer: 2000,
    showCancelButton: false,
    showConfirmButton: false
});
Suhas Bachhav
  • 283
  • 1
  • 6
  • 28
0

One more way to do the same.

Swal.fire({
  type: 'error',
  title: 'Cancelled',
  text: 'Your offer is safe ',
  showConfirmButton: false,
  timer: 2000
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>

Upgrading to v9.x of SweetAlert2.

Breaking change - rename type to icon

Swal.fire({
  icon: 'error',
  title: 'Cancelled',
  text: 'Your offer is safe ',
  showConfirmButton: false,
  timer: 2000
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
Penny Liu
  • 7,720
  • 5
  • 40
  • 66
-1

Before adding any buttons,clear all the buttons and then re-add them like(assuming the Alert name is 'A') -

A.getButtonTypes().clear();
ButtonType OpenStorage=new ButtonType("Open Storage");
A.getButtonTypes().addAll(OpenStorage,ButtonType.CANCEL,ButtonType.NEXT);

Hope it'll help!!!

Ragib
  • 87
  • 7