Andrufus / yii2-sweet-alert

Alert Widget for Yii 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alert Widget for Yii 2

Alert widget based on SweetAlert

Latest Stable Version Total Downloads License

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json.

Usage

Once the extension is installed, simply add widget to your page as follows:

  1. Default usage, render all flash messages stored in session flash via Yii::$app->session->setFlash().
echo Alert::widget(); 
  1. Example with custom message and custom callback:
echo \yii2mod\alert\Alert::widget([
    'options' => [
        'useSessionFlash' => false,
        '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"); 
    }')
]);

Alert Options

You can find them on the options page

About

Alert Widget for Yii 2

License:MIT License


Languages

Language:PHP 100.0%