2017 © Pedro Peláez
 

yii2-extension yii2-sweet-alert

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

image

csabike2/yii2-sweet-alert

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

  • Wednesday, September 27, 2017
  • by csabike2
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % 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 csabike2/yii2-sweet-alert "^2.0.3"

or add, (*6)

"csabike2/yii2-sweet-alert": "^2.0.3"

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', [
    'options' => [
        'timer' => null,
        'type' => \csabike2\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"); 
    }')
]);

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

echo Alert::widget();

For render the custom widget you can use the same configuration like before:, (*11)

// A replacement for the "prompt" function

echo \csabike2\alert\Alert::widget([
    'useSessionFlash' => false,
    'options' => [
        'timer' => null,
        'type' => \csabike2\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' => [
        'csabike2\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

27/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 Chepurnoi
by Csaba Istvan Berta

yii2 yii2 sweet alert yii2 alert

27/09 2017

dev-develop

dev-develop

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoi
by Csaba Istvan Berta

yii2 yii2 sweet alert yii2 alert

26/09 2017

2.0.3.2

2.0.3.2

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoi
by Csaba Istvan Berta

yii2 yii2 sweet alert yii2 alert

26/09 2017

2.0.3.1

2.0.3.1

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoi
by Csaba Istvan Berta

yii2 yii2 sweet alert yii2 alert

25/09 2017

2.0.3

2.0.3.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoi
by Csaba Istvan Berta

yii2 yii2 sweet alert yii2 alert

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