How can we disable sweetalert select box option.?

285 Views Asked by At

I used sweetalert in my jquery web application. And I'm showing that with select box. That's sweetalert options like below.

swal({
  title: 'Select field validation',
  input: 'select',
  inputOptions: {
      apples: 'Apples',
      bananas: 'Bananas',
      grapes: 'Grapes',
      oranges: 'Oranges'
  },
  inputPlaceholder: 'Select a fruit',
  showCancelButton: true,
})

But, I want to disable particular select box option in that sweetalert select box.

If anybody know that solution means, Kindly share here.

1

There are 1 best solutions below

0
subrahmanyam ravi On BEST ANSWER

Use the didOpen method it will call after swal select box init

 swal({
      title: 'Select field validation',
      input: 'select',
      inputOptions: {
        apples: 'Apples',
        bananas: 'Bananas',
        grapes: 'Grapes',
        oranges: 'Oranges'
      },
      inputPlaceholder: 'Select a fruit',
      showCancelButton: true,
      didOpen: () => {
        $('.swal2-select option:first').attr('disabled', true);
      }
 });