sweetalert2

✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦

MIT License

Downloads
2.6M
Stars
16.8K
Committers
122
sweetalert2 - Using Promise, the right way

Published by limonte over 8 years ago

Breaking change in 4.0.0

SweetAlert2 now rejects Promise reject(dismiss) in cases:

  • Cancel button was clicked (dismiss will be "cancel")
  • Overlay click ("overlay")
  • Esc press ("esc")
  • Timer ("timer")

Before 4.0.0 Promise handling:

swal({title: 'Are you sure?', showCancelButton: true}).then(
  function(isConfirm) {
    if (isConfirm === true) {
      // handle Confirm button click
    } else if (isConfirm === false) {
      // handle Cancel button click
    } else {
      // Esc, close button or outside click, isConfirm is undefined
    }
  }
);

Starting with v4.0.0 Promise will be resolved in case of Confirm button was clicked and rejected with dismiss parameter on all other cases:

swal({title: 'Are you sure?', showCancelButton: true}).then(
  function(result) {
    // handle Confirm button click
    // result is an optional parameter, needed for modals with input
  }, function(dismiss) {
    // dismiss can be 'cancel', 'overlay', 'esc' or 'timer'
  }
);
sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 -

Published by limonte over 8 years ago

Add Promise support for input-radio and input-select

sweetalert2 -

Published by limonte over 8 years ago

Add input type file

sweetalert2 -

Published by limonte over 8 years ago

Add showLoaderOnConfirm parameter

sweetalert2 -

Published by limonte over 8 years ago

Add resetDefaults() to chaining modals example

sweetalert2 -

Published by limonte over 8 years ago

Add queue() method for chaining modals.

sweetalert2 -

Published by limonte over 8 years ago

  • add resetDefaults() method
  • switch to stefanpenner/es6-promise
  • add NPM postinstall script to ignore changes in dist by default
  • change main JS file in bower.json
sweetalert2 -

Published by limonte over 8 years ago

  • small fix for use 3rd party animations.
  • remove not used param lastFocusedButton.
sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 - ES6 module structure

Published by limonte over 8 years ago

Helper functions and some static data are moved out of the main source file and into their own respective utils/*.js files. This kind of approach will help in the long run as more features are added, the main scope isn't going to be completely bloated.

The main lengthy block of code that sets the users provided options is replaced it with the extend() helper.

sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 -

Published by limonte over 8 years ago

Removed module specific code from the source and added it to a package wrapper instead. This allows exporting for many different bundler types, and clean logic.

  • reimplemented production minification
  • explicitly listing module files for npm
sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 - Export sweet alert as module

Published by limonte over 8 years ago

If window is detected it will automatically extend it with sweetAlert and swal

Many thanks to @Tonkpils

sweetalert2 -

Published by limonte over 8 years ago

sweetalert2 -

Published by limonte over 8 years ago

Bower compatibility update