yii2-dynamic-fields

Widget for display dynamic fields, adding and removing their using Pjax.

  • Owner: bupy7/yii2-dynamic-fields
  • Platform:
  • License:: BSD 3-Clause "New" or "Revised" License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

yii2-dynamic-fields

Widget for display dynamic fields, adding and removing their use Pjax.

Screenshot

Installation

The preferred way to install this extension is through composer.

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:

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' => ,
    'form' => $form,
    'models' => $models,
    'attribute' => 'attribute',
]);

echo Html::submitButton('Save', ['class' => 'btn btn-success']);

ActiveForm::end();

Added following code to your controller:

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.

Main metrics

Overview
Name With Ownerbupy7/yii2-dynamic-fields
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:BSD 3-Clause "New" or "Revised" License
所有者活动
Created At2015-03-25 18:00:25
Pushed At2018-03-26 05:38:51
Last Commit At2018-03-26 10:36:56
Release Count3
Last Release Namev1.0.2 (Posted on )
First Release Namev1.0.0 (Posted on )
用户参与
Stargazers Count52
Watchers Count12
Fork Count17
Commits Count22
Has Issues Enabled
Issues Count2
Issue Open Count2
Pull Requests Count0
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private