Usage of SweetAlert2 in Elbrus version

SweetAlert2 is a powerful JavaScript library designed to replace native browser alerts with customizable, and responsive pop-up modals in SuiteCommerce Advanced (SCA) websites. It significantly enhances the user experience by supporting features such as icons, animations, and fully configurable buttons—making it ideal for confirmations, notifications, and form-related interactions.

Example Implementation

The example below demonstrates how to use SweetAlert2 in Elbrus version to show a success message when an item is added to the cart on an SCA website:

  1. Add the below CDN links of sweet alert2 inside the initialize method.

if (JSON.stringify(new XMLSerializer().serializeToString(document)).indexOf(‘https://cdn.jsdelivr.net/npm/sweetalert2@3.0.0/dist/sweetalert2.min.js’) === 1) {

        jQuery(‘head’).append(jQuery(‘<script src=”https://cdn.jsdelivr.net/npm/sweetalert2@3.0.0/dist/sweetalert2.min.js”></script>’));

      }

      if (JSON.stringify(new XMLSerializer().serializeToString(document)).indexOf(‘https://cdn.jsdelivr.net/npm/sweetalert2@3.0.0/dist/sweetalert2.min.css’) === 1) {

        jQuery(‘head’).append(jQuery(‘<link href=”https://cdn.jsdelivr.net/npm/sweetalert2@3.0.0/dist/sweetalert2.min.css” rel=”stylesheet” />’));

      }

  1. Pass the message content as an object inside the swal() method.

swal({

              title: ‘Cart Limit Reached!’,

              text: “Your cart currently contains 100 SKUs, which is the maximum supported per order. To purchase additional items, please create a new order.”,

              type: ‘warning’,

              confirmButtonText: ‘Close’

            });

Alert type

  1. Success – ‘success’
  2. Error – ‘error’
  3. Info – ‘info’
  4. Warning – ‘warning’
  5. Question – ‘question’

Common properties used in the object passed to swal()

  1. title – Sets the main heading of the alert modal.
  2. text – Provides the message or description shown below the title.
  3. icon or type – Defines the alert type: 'success', 'error', 'warning', 'info', or 'question'.
  4. confirmButtonText – Customizes the text on the confirmation button.
  5. cancelButtonText – Sets the label for the cancel button (used with showCancelButton).
  6. showCancelButton – A boolean that determines whether to display a cancel button.
  7. html – Allows you to use HTML instead of plain text for richer content.
  8. footer – Adds a footer section to the modal, often used for links or notes.
  9. timer – Automatically closes the alert after a specified time (in milliseconds).
  10. input – Adds an input field for user responses (e.g., 'text', 'email', 'select').
  11. customClass – Lets you apply custom CSS classes to style different parts of the modal.

Leave a comment

Your email address will not be published. Required fields are marked *