Changes
Title
unchanged
Simple way to implement Dynamic Tabular Inputs
Category
unchanged
Tutorials
Yii version
changed
2.0
Tags
changed
dynamic, tabular, Forms
Content
changed
![Example Form](<img width="660px" src="https://camo.githubusercontent.com/d753d4420de760ba8e72405647c75462ca63f6f8/687474703a2f2f736e61672e67792f644d50786d2e6a7067
"Example form")" alt="grid">
On my experience in Yii IRC, once in a while there would be someone that asks about how to create pages that handles 1 main model and its submodel and saving the changes in a single click. i wrote the example application on top of Yii2's basic application template that you can download here (i suggest you also run the acceptance test to see it in action):[...]
7. save!
```php
/**
* Creates a new Receipt model.[...]
to support the update part, we need to add particular scenarios to our model, here's my ReceiptDetail code
```php
/**
* This is the model class for table "receipt_detail".[...]
call save() (for UPDATE or CREATE)
7. Done!
```php
/**
* Updates an existing Receipt model.[...]
4. handle the delete button, if the row represents a ReceiptDetail has a scenario of update (this means it has been loaded from the DB) then we just mark it for deletion by making the updateType to DELETE
otherwise if this is a new row that you just added using the addRow button, just remove the row entirely from the HTML page
```php
use app\models\Receipt;
use app\models\ReceiptDetail;
use yii\helpers\Html;
use yii\widgets\ActiveForm;[...]