2017 © Pedro Peláez
 

yii2-extension yii2-sweet-alert

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

image

yii2mod/yii2-sweet-alert

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  • Tuesday, September 12, 2017
  • by disem
  • Repository
  • 6 Watchers
  • 35 Stars
  • 17,216 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 2 Open issues
  • 6 Versions
  • 14 % Grown

The README.md

, (*1)

Yii2 Alert Widget


Alert widget based on SweetAlert, (*2)

Latest Stable Version Total Downloads License Build Status, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist yii2mod/yii2-sweet-alert "*"

or add, (*6)

"yii2mod/yii2-sweet-alert": "*"

to the require section of your composer.json., (*7)

Usage

For render the message from session flash you can use the following code:, (*8)

1) Set the message in your action, for example:, (*9)

Yii::$app->session->setFlash('success', 'This is the message');

2) Simply add widget to your page as follows:, (*10)

echo Alert::widget();

For render the custom message you can use the following code:, (*11)

// A replacement for the "prompt" function

echo \yii2mod\alert\Alert::widget([
    'useSessionFlash' => false,
    'options' => [
        'timer' => null,
        'type' => \yii2mod\alert\Alert::TYPE_INPUT,
        'title' => 'An input!',
        'text' => "Write something interesting",
        'confirmButtonText' => "Yes, delete it!",
        'closeOnConfirm' => false,
        'showCancelButton' => true,
        'animation' => "slide-from-top",
        'inputPlaceholder' => "Write something"
    ],
    'callback' => new \yii\web\JsExpression(' function(inputValue) { 
                if (inputValue === false) return false;      
                if (inputValue === "") { 
                    swal.showInputError("You need to write something!");     
                    return false;   
                }      
                swal("Nice!", "You wrote: " + inputValue, "success"); 
    }')
]);

You can also change the theme of SweetAlert!, (*12)

To change the theme, you can configure the assetManager array in your application configuration:, (*13)

// twitter theme

'assetManager' => [
    'bundles' => [
        'yii2mod\alert\AlertAsset' => [
            'css' => [
                'dist/sweetalert.css',
                'themes/twitter/twitter.css',
            ]
        ],
    ],
]

You can override the Yii2 default data-confirm popup by the following code:, (*14)

The basics are to include the asset, then add this JS:, (*15)

/**
 * Override the default yii confirm dialog. This function is
 * called by yii when a confirmation is requested.
 *
 * @param message the message to display
 * @param okCallback triggered when confirmation is true
 * @param cancelCallback callback triggered when cancelled
 */
yii.confirm = function (message, okCallback, cancelCallback) {
    swal({
        title: message,
        type: 'warning',
        showCancelButton: true,
        closeOnConfirm: true,
        allowOutsideClick: true
    }, okCallback);
};

Alert Options

You can find them on the options page, (*16)

The Versions

12/09 2017

dev-master

9999999-dev

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy
by Igor Chepurnoi

yii2 yii2 sweet alert yii2 alert yii2 sweetalert

12/09 2017

1.3

1.3.0.0

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoi

yii2 yii2 sweet alert yii2 alert

27/07 2016

1.2

1.2.0.0

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 alert yii2 alert sweet alert

18/07 2016

1.1

1.1.0.0

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 module

01/06 2016

1.0.1

1.0.1.0

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 module

24/09 2015

1.0

1.0.0.0

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

  Sources   Download

MIT

The Requires

  • bower-asset/sweetalert *

 

by Igor Chepurnoy

yii2 module