2017 © Pedro Peláez
 

yii2-extension yii2-ajax

image

antkaz/yii2-ajax

  • Saturday, June 16, 2018
  • by antkaz
  • Repository
  • 2 Watchers
  • 1 Stars
  • 322 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 7 Versions
  • 125 % Grown

The README.md

yii2-ajax

This extension allows you to create forms in the Twitter Bootstrap modal window., (*1)

Documentation is at docs/README.md, (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Run, (*4)

php composer.phar require antkaz/yii2-ajax

or add, (*5)

"antkaz/yii2-ajax": "~1.2"

to the require section of your composer.json file., (*6)

Basic usage

  1. Аdd the modal widget to your view file:, (*7)

    <?= \antkaz\ajax\Modal::widget([
        'id' => 'modal',
        'clientEvents' => [
            'submit.success.bs.modal' => 'function(event, body) {$(this).modal("hide")}'
        ]
    ]); ?>
    
  2. Add a link that will open the modal window:, (*8)

    <?= \yii\bootstrap\Html::a('Create', ['create'], [
        'class' => 'btn btn-success',
        'data-toggle' => 'ajax-modal', // outputs the result to the modal window
        'data-target' => '#modal', // ID modal
        'data-title' => 'Create item' // custom modal title
    ]); ?>
    
  3. Add the data-ajax attribute in the ActiveForm options:, (*9)

     [
            'data-ajax' => 1
        ],
    ]); ?>
    
    // your fields
    
    
    
  4. Create an action in your controller that will handle this request:, (*10)

    public function actionCreate()
    {
        $model = new Model();
    
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['index']); // optional
        }
    
        return $this->renderView('create', [
            'model' => $model,
        ]);
    
    }
    
    protected function renderView($view, $params = [])
    {
        if (Yii::$app->request->isAjax) {
            return $this->renderAjax($view, $params);
        }
        return $this->render($view, $params);
    }
    

Attributes

Link attributes for loading the modal window:, (*11)

  • data-toggle - Toggle for enabled ajax-modal (required value ajax-modal);
  • data-target - Bootstrap modal selector;
  • data-title - Modal title;
  • data-gridview - Yii2 GridView selector for group operations.

Events

Added the following events, in addition to those that already exist, (*12)

  • submit.success.bs.modal - This event is triggered after the form has been successfully submitted. The second parameter is the content of the response:, (*13)

    $('#myModal').on('submit.success.bs.modal', function (event, bodyResponse) {
      // do something...
    })
    

The Versions

16/06 2018

dev-master

9999999-dev https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal

16/06 2018

v1.3

1.3.0.0 https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal

26/04 2018

v1.2.2

1.2.2.0 https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal

25/04 2018

v1.2.1

1.2.1.0 https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal

24/04 2018

v1.2

1.2.0.0 https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal

13/02 2018

v1.1

1.1.0.0 https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal

12/02 2018

v1.0

1.0.0.0 https://github.com/antkaz/yii2-ajax

  Sources   Download

MIT

The Requires

 

by Anton Kazarinov

yii2 bootstrap ajax modal