Alert widget based on SweetAlert
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.
Once the extension is installed, simply add widget to your page as follows:
- Default usage, render all flash messages stored in session flash via Yii::$app->session->setFlash().
echo Alert::widget();
- 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");
}')
]);
You can find them on the options page