5

I can set inputType as password. What are the other input Types supported..?

       swal({
            title: "Are you sure?",             
            type: "input",
            inputType: "checkbox",             
            showCancelButton: true,
            closeOnConfirm: true,                
        }, function () {
            swal("", "You did it", "success");
        });

the checkbox inputType is not supported in swal..

Sushil Chaskar
  • 51
  • 1
  • 1
  • 3

1 Answers1

13

There's a nice way to use checkbox modal type in SweetAlert2:

Swal.fire({
  title: 'Do you have a bike?',
  input: 'checkbox',
  inputPlaceholder: 'I have a bike'
}).then((result) => {
  if (result.isConfirmed) {
    if (result.value) {
      Swal.fire({icon: 'success', text: 'You have a bike!'});
    } else {
      Swal.fire({icon: 'error', text: "You don't have a bike :("});
    }
  } else {
    console.log(`modal was dismissed by ${result.dismiss}`)
  }
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

PS. notice that SweetAlert2 is a little bit different from SweetAlert, check the simple migration guide: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
  • How to do this if there is more than one input field in the dialog? i.e. "Enter Name" (string) and Add To Mailing List (checkbox)? – GGizmos Jan 10 '23 at 21:21