Skip to content

Commit

Permalink
ModalAjax for Bootstrap 4 Modal
Browse files Browse the repository at this point in the history
- it depends on `yiisoft/yii2-bootstrap4` instead of `yiisoft/yii2-bootstrap`
- use attribute `title` instead of `header` :
echo ModalAjax::widget([
    ...
    "title" => "Modal's header",
    ...
]);
  • Loading branch information
ivankff committed Mar 22, 2019
1 parent 27903f2 commit ceb59b9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
/.idea
/phpunit.xml
/composer.lock
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Total Downloads](https://poser.pugx.org/loveorigami/yii2-modal-ajax/downloads)](https://packagist.org/packages/loveorigami/yii2-modal-ajax)
[![License](https://poser.pugx.org/loveorigami/yii2-modal-ajax/license)](https://packagist.org/packages/loveorigami/yii2-modal-ajax)

A wrapper around Yii2 Bootstrap Modal for using an ActiveForm via AJAX inside.
A wrapper around Yii2 Bootstrap 4 Modal for using an ActiveForm via AJAX inside.

## Installation
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
Expand Down Expand Up @@ -74,14 +74,14 @@ use lo\widgets\modal\ModalAjax;

echo ModalAjax::widget([
'id' => 'createCompany',
'header' => 'Create Company',
'title' => 'Create Company',
'toggleButton' => [
'label' => 'New Company',
'class' => 'btn btn-primary pull-right'
],
'url' => Url::to(['/partner/default/create']), // Ajax view with form to load
'ajaxSubmit' => true, // Submit the contained form as ajax, true by default
// ... any other yii2 bootstrap modal option you need
// ... any other yii2 bootstrap 4 modal option you need
]);
```

Expand All @@ -93,7 +93,7 @@ use lo\widgets\modal\ModalAjax;

echo ModalAjax::widget([
'id' => 'createCompany',
'header' => 'Create Company',
'title' => 'Create Company',
'toggleButton' => [
'label' => 'New Company',
'class' => 'btn btn-primary pull-right'
Expand Down Expand Up @@ -182,7 +182,7 @@ Pjax::end();

## Plugin Events

On top if the basic twitter bootstrap modal events the following events are triggered
On top if the basic twitter bootstrap 4 modal events the following events are triggered


### `kbModalBeforeShow` (ModalAjax::EVENT_BEFORE_SHOW)
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ajax-modal"
],
"homepage": "https://github.com/loveorigami/yii2-modal-ajax",
"version": "3.7",
"version": "4.0",
"type": "yii2-extension",
"license": "MIT",
"authors": [
Expand All @@ -21,6 +21,10 @@
"homepage": "https://loveorigami.info"
}
],
"require": {
"yiisoft/yii2": "~2.0",
"yiisoft/yii2-bootstrap4": "~2.0.0"
},
"autoload": {
"psr-4": {
"lo\\widgets\\modal\\": "src/"
Expand Down
30 changes: 4 additions & 26 deletions src/ModalAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace lo\widgets\modal;

use yii\base\InvalidConfigException;
use yii\bootstrap\Modal;
use yii\bootstrap4\Modal;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\JsExpression;
Expand Down Expand Up @@ -82,26 +81,6 @@ class ModalAjax extends Modal
*/
protected $mode = self::MODE_SINGLE;

/**
* Renders the header HTML markup of the modal
*
* @return string the rendering result
*/
protected function renderHeader()
{
$button = $this->renderCloseButton();
if ($button !== null) {
$this->header = $button . "\n<span>" . $this->header . "</span>\n";
}
if ($this->header !== null) {
Html::addCssClass($this->headerOptions, ['widget' => 'modal-header']);

return Html::tag('div', "\n" . $this->header . "\n", $this->headerOptions);
} else {
return null;
}
}

/**
* @inheritdocs
*/
Expand Down Expand Up @@ -137,7 +116,7 @@ public function run()
break;

case self::MODE_MULTI:
$this->registerMultyModal($id, $view);
$this->registerMultiModal($id, $view);
break;
}

Expand All @@ -159,7 +138,6 @@ protected function registerSingleModal($id, $view)
$view->registerJs("
jQuery('#$id').kbModalAjax({
url: '$url',
size:'sm',
ajaxSubmit: ".($this->ajaxSubmit ? "true" : "false")."
});
");
Expand All @@ -169,7 +147,7 @@ protected function registerSingleModal($id, $view)
* @param $id
* @param View $view
*/
protected function registerMultyModal($id, $view)
protected function registerMultiModal($id, $view)
{
$view->registerJs("