missing select options with Sweet Alert

Cheri picture Cheri · Apr 7, 2017 · Viewed 16.4k times · Source

This may be a ServiceNow issue, but I added a Sweet Alert to show a select box just so I can gather a value to pass on to the next record... but the select box is not showing, the popup is there just no box or options. What am I missing? Screenshot: Select Box Alert

Thanks so much, super frustrated with something I thought would be simple to add :)

Answer

Limon Monte picture Limon Monte · Apr 7, 2017

Your code snippet is for SweetAlert2 and most probably your issue is that you're including the original unmaintained SweetAlert plugin, which doesn't have the select-box support.

Your code works just fine with included SweetAlert2 library:

Swal.fire({
  title: 'Select Outage Tier',
  input: 'select',
  inputOptions: {
    '1': 'Tier 1',
    '2': 'Tier 2',
    '3': 'Tier 3'
  },
  inputPlaceholder: 'required',
  showCancelButton: true,
  inputValidator: function (value) {
    return new Promise(function (resolve, reject) {
      if (value !== '') {
        resolve();
      } else {
        resolve('You need to select a Tier');
      }
    });
  }
}).then(function (result) {
  if (result.isConfirmed) {
    Swal.fire({
      icon: 'success',
      html: 'You selected: ' + result.value
    });
  }
});
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>