vsk/modal-form

Modal form widget for Yii2

Installs: 1 336

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 2

Open Issues: 0

Language:JavaScript

v1.0.16 2019-02-28 09:30 UTC

This package is auto-updated.

Last update: 2024-11-29 00:24:57 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

composer require vsk/modal-form

or add

"vsk/modal-form" : "~1.0.0"

to the require section of your application's composer.json file.

Usage

Edit modal example

Include in controller

class TestController extends Controller
{

    public function actions()
    {
        return [
            'modal-form' => [
                'class' => ModalFormAction::class,
                'getBody' => function ($action) {
                    return $this->render('@vendor/vsk/modal-form/src/test/views/modal-list');
                },
                'getTitle' => function() {
                    return 'Список тестовых данных';
                },
            ],
            'modal-form-update' => [
                'class' => ModalFormAction::class,
                'getBody' => function ($action) {
                    return $this->render('@vendor/vsk/modal-form/src/test/views/update', [
                        'model' => $action->getModel(),
                    ]);
                },
                'getTitle' => function() {
                    return 'title';
                },
                'getModel' => function () {
                    $id = \Yii::$app->request->get('id');
                    return Test::findOne($id);
                },
                'submitForm' => function ($action) {
                    $model = $action->getModel();
                    $model->load(\Yii::$app->request->post());
                    return $model->save();
                }
            ],
        ];
    }
}

Include in you view

<?php

echo \vsk\modalForm\ModalFormWidget::widget([
                     'template' => function ($widget) {
                         $id = $widget->getId();
                         return "<button id='{$id}' data-modal-url='/adminx24/test/modal-form'>TEST</button>";
                     }
                 ]);