mix8872 / yii2-repeater
The html repeater (forked)
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Type:yii2-extension
Requires
- php: >=7.1
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-11-09 00:42:48 UTC
README
You can use this extension to duplicate the contents of a form and also other contents
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require mix8872/yii2-repeater
or add
"mix8872/yii2-repeater": "*"
to the require section of your composer.json
file.
Configuration
Add modules declaration to your config file for web config:
<?php return [ // ... your config 'modules' => [ 'repeater'=> [ 'class' => \mix8872\repeater\Repeater::class ], ], 'bootstrap' => [ 'repeater' // add module id to bootstrap for proper aliases and url routes binding ]
Usage
Example view:
<?= \mix8872\repeater\widgets\RepeaterWidget::widget([ 'className' => \app\models\TestRepeater::class, 'modelView' => '@app/views/site/repeater', 'models' => [ //list of your models new \app\models\TestRepeater(), ], 'btnNewTitle' => 'Add main container', 'addCallback' => new \yii\web\JsExpression(" function(data){ console.log(data); } "), 'removeCallback' => new \yii\web\JsExpression(" function(data){ console.log(data); } ") ]);?>
Example your model:
<?php class TestRepeater extends Model { public $title; public $text; public function rules() { return [ [['date', 'text'], 'safe'] ]; } } ?>
Example view of model:
<?php /** @var \app\models\TestRepeater $model */ /** @var int $id */ ?> <table border="1" width="100%"> <tbody> <tr> <td> <div class="form-group field-posts-title required has-success"> <?= \yii\helpers\Html::activeTextInput($model, "title[$id]")?> </div> <?= CKEditor::widget([ 'name' => "TestRepeater[text][$id]", 'id' => 'cke' . $id, 'options' => ['rows' => 3], 'preset' => 'basic' ])?> </td> </tr> <tr> <td> <?= \mix8872\repeater\widgets\RepeaterWidget::widget([ 'className' => \app\models\TestRepeaterTwo::class, 'modelView' => '@app/views/site/repeaterTwo', 'models' => [ new \app\models\TestRepeaterTwo(), ], 'additionalData' => [ 'container' => "[two][$id]", 'parentId' => $id ], 'btnNewTitle' => 'Add second container', 'addCallback' => new \yii\web\JsExpression(" function(data){ console.log(data); } "), 'removeCallback' => new \yii\web\JsExpression(" function(data){ console.log(data); } ") ]);?> </td> </tr> </tbody> </table>