yii2-dynamic-fields

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

  • 所有者: bupy7/yii2-dynamic-fields
  • 平台:
  • 許可證: BSD 3-Clause "New" or "Revised" License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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.

主要指標

概覽
名稱與所有者bupy7/yii2-dynamic-fields
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2015-03-25 18:00:25
推送於2018-03-26 05:38:51
最后一次提交2018-03-26 10:36:56
發布數3
最新版本名稱v1.0.2 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數52
關注者數12
派生數17
提交數22
已啟用問題?
問題數2
打開的問題數2
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?