conquer / modal
Extension for the Yii2 framework
Package info
github.com/borodulin/yii2-modal-form
Language:JavaScript
Type:yii2-extension
pkg:composer/conquer/modal
Requires
- php: ^7.4 || ^8.0
- yiisoft/yii2: ^2.0.4
Requires (Dev)
None
Suggests
- yiisoft/yii2-bootstrap: Bootstrap 3
- yiisoft/yii2-bootstrap4: Bootstrap 4
- yiisoft/yii2-bootstrap5: Bootstrap 5
Provides
None
Conflicts
None
Replaces
None
README
Description
This extension allows you to quickly add full-featured modal forms to your appllication. Main featues are:
- Based on bootstrap modal forms.
- Allows quickly add behavior to interact with viewing and updating data in modal dialogs.
- Catch form post events, converts them to ajax request and display results in the same modal dialog.
Requirements
- PHP 7.4 or 8.x
- Yii 2.0.4 or newer (2.0.x)
Installation
Install the extension via Composer:
composer require conquer/modal:^1.4
Usage
Somewhere in the main layout
\conquer\modal\ModalForm::widget([ 'selector' => '.modal-form', ]);
Bootstrap 3, 4 and 5 are supported. The version is detected from the installed Yii Bootstrap extension
(yiisoft/yii2-bootstrap, yii2-bootstrap4 or yii2-bootstrap5); set bsVersion to choose it explicitly:
\conquer\modal\ModalForm::widget([ 'selector' => '.modal-form', 'bsVersion' => \conquer\modal\ModalForm::BS_5, ]);
Whenever you want to add behavior to tag a, just add class 'modal-form'
echo Html::a('Some modal action', ['controller/action'], ['class' => 'modal-form']);
To improve traffic data and error exceptions you need to control layout rendering when ajax requests. I recommend you to override default rendering in your controllers:
class Controller extends \yii\web\Controller { /** * Exclude layout rendering when ajax requests */ public function render($view, $params = []) { if (\Yii::$app->request->isAjax) { return $this->renderPartial($view, $params); } return parent::render($view, $params); } }
Client Options
To add client options use clientOptions key. Available client options are: id, class, tabindex, backdrop, keyboard.
- Id key replaces existing auto generated id attribute.
- Class key adds classes to html class attribute.
- Tabindex key replaces existing default tabindex html attribute (-1), when false, then no tabindex attribute appears.
- Backdrop and keyboard keys set the Bootstrap
backdrop(true,falseor'static') andkeyboardoptions of the modal.
The name and value of the clicked submit button are sent with the form, so several submit buttons (for example "Save" and "Apply") can be told apart on the server.
\conquer\modal\ModalForm::widget([
'selector' => '.modal-form',
'clientOptions' => [
'id' => 'sample-unique-id',
'class' => 'sample-class1 sample-class2',
'tabindex' => false
]
]);
License
conquer/modal is released under the MIT License. See the bundled LICENSE for details.