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
[...]
5. check if the addRow button is clicked instead of the create button, if so... add a new ReceiptDetail instance to the $modelDetails
and go to the create page
6. if it's actually the create button that has been submitted, validate each $modelDetails and the $model which you have assigned the Receipt
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;[...]