Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bupy7/yii2-dynamic-fields
Widget for display dynamic fields, adding and removing their using Pjax.
https://github.com/bupy7/yii2-dynamic-fields
dynamic fields yii2
Last synced: 3 months ago
JSON representation
Widget for display dynamic fields, adding and removing their using Pjax.
- Host: GitHub
- URL: https://github.com/bupy7/yii2-dynamic-fields
- Owner: bupy7
- License: bsd-3-clause
- Archived: true
- Created: 2015-03-25T18:00:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-26T05:38:51.000Z (almost 7 years ago)
- Last Synced: 2024-09-17T23:13:38.584Z (4 months ago)
- Topics: dynamic, fields, yii2
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 52
- Watchers: 13
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-yii2 - bupy7/yii2-dynamic-fields - dynamic-field/)) (Widgets 小部件)
README
yii2-dynamic-fields
==================
Widget for display dynamic fields, adding and removing their use Pjax.![Screenshot](screenshot.png)
Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist bupy7/yii2-dynamic-fields "*"
```or add
```
"bupy7/yii2-dynamic-fields": "*"
```to the require section of your `composer.json` file.
Usage
-----Add following code to your view:
```php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use bupy7\dynafields\DynaFields;$form = ActiveForm::begin(['action' => ['index']]);
echo DynaFields::widget([
'urlAdd' => ['your-action-add'],
'urlRemove' => ['your-action-remove'],
'inputMethod' => 'textInput',
'inputMethodArgs' => [['maxlength' => true]],
'form' => $form,
'models' => $models,
'attribute' => 'attribute',
]);echo Html::submitButton('Save', ['class' => 'btn btn-success']);
ActiveForm::end();
```Added following code to your controller:
```php
use Yii;
use yii\base\Model;/**
* Render form.
*/
public function actionIndex()
{
$models = ModelName::find()->all();
if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) {
for ($i = 0; $i != count($models); $i++) {
$models[$i]->save(false);
}
return $this->redirect(['index']);
}
return $this->render('index', ['models' => $models]);
}/**
* Create new model.
*/
public function actionYourActionAdd()
{
$model = new ModelName;
$model->save(false);
return $this->actionIndex();
}/**
* Delete model.
* @param int $id
*/
public function actionYourActionRemove($id)
{
ModelName::findOne($id)->delete();
return $this->actionIndex();
}
```##License
yii2-dynamic-fields is released under the BSD 3-Clause License.