Browse documentation

Live Components

The bundle ships two Twig Live Components:

  • SweetAlert:ConfirmButton
  • SweetAlert:InputModal

Both components dispatch ux-sweet-alert:alert:added, which is already handled by the bundled Stimulus controller.

ConfirmButton

  <twig:SweetAlert:ConfirmButton
    title="Archive conversation?"
    text="This action cannot be undone."
    icon="warning"
    showCancelButton="true"
    confirmButtonText="Archive"
    cancelButtonText="Keep it"
/>

Main props

Prop Purpose
title Alert title shown in the modal.
text Supporting text.
icon SweetAlert icon value such as success, error, or warning.
showCancelButton Whether the modal should expose a cancel action.
callback Optional browser callback function name.
customClass JSON-encoded SweetAlert `customClass` object.
confirmButtonText Confirm button label.
cancelButtonText Cancel button label.

InputModal

InputModal exposes the same core props, plus input-specific options such as inputType, inputLabel, inputPlaceholder, inputValue, inputOptions, inputAttributes, validationMessage, and returnInputValueOnDeny.

  <twig:SweetAlert:InputModal
    title="Choose a role"
    text="This will be applied immediately."
    inputType="select"
    inputLabel="Role"
    inputOptions='{"admin":"Admin","editor":"Editor"}'
    inputValue="editor"
/>

Browser callback mode

If callback points to a browser function name, the frontend controller calls it with the SweetAlert result object:

  <twig:SweetAlert:ConfirmButton
    title="Confirm deletion"
    callback="handleDeletionConfirmation"
>
    Delete
</twig:SweetAlert:ConfirmButton>

<script>
  function handleDeletionConfirmation(result) {
    if (result.isConfirmed) {
      console.log('Confirmed')
    }
  }
</script>

Server-side Live action mode

If there is no browser callback, the Stimulus controller tries to resolve the current Live Component and invoke callbackAction with the modal result and data-live-item-*-param values.

Extending ConfirmButton

Override callbackAction() when you need custom server-side logic after confirmation.

Extending InputModal

Override the protected onResult(Result $result, array $args = []) hook for result handling.