dench/yii2-modal

Modal widget for Yii2

Installs: 92

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2020-07-02 15:13 UTC

This package is auto-updated.

Last update: 2024-04-29 03:53:43 UTC


README

Modal widget for Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist dench/yii2-modal "*"

or add

"dench/yii2-modal": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

<button data-modal="/site/modal-test" data-modal-size="modal-sm">Open Modal</button>

<button onclick="openModal('/site/modal-test', { size: 'modal-lg' });">Open Modal</button>

<button onclick="openModal(null, { title: 'Title', body: 'Body' });">Open Modal</button>

<?= \dench\modal\Modal::widget(); ?>
public function actionModalTest()
{
    $footer = Html::button('Close', ['class' => 'btn btn-secondary', 'data-dismiss' => 'modal']);

    $model = new ModelForm();

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        Yii::$app->session->setFlash('success', 'Success');
    } else {
        $footer .= Html::submitButton('Ok', ['class' => 'btn btn-primary']);
    }

    $data = [
        'title' => 'Title',
        'body' => $this->renderAjax('modal-test', [
            'model' => $model,
        ]),
        'footer' => $footer,
    ];

    return Json::encode($data);
}

ReCaptcha

use himiklab\yii2\recaptcha\ReCaptcha;

echo ReCaptcha::widget();

$js = <<<JS
if (typeof grecaptcha !== 'undefined') {
    recaptchaOnloadCallback();
}
JS;
$this->registerJs($js);