Edit/update multiple records at once

Hi,

I have an issue here that I am not sure how to work out.

For example I have a groups. And each group has 4 or more products. The thing I want to do is I want to be able to show and edit all products within a group at once. Normally I would loop through all the products and build the form fields. But I can not do this with an active form. Problem that will occur is that all fields are validated at once when I do a change.

So i am looking for a solution where I can edit all products within a group in a form. And I want all items to be validated as well like an active form normally does.

Does anyone have any tips for me?

Best regards.

You can do this with active form. The problem is that you have the same $model and $attribute for each one. This will make each of them have the same id and thus validating all of them as the same element (at one time). You need to loop thgourh them and assign a way to uniquely identify each form field.


<?php foreach($model as $i=>$item): ?>        <?= $form->field($model,"[$i]name"); ?>

<?php endforeach; ?>

So the $i would be the unique identifier for active form fileds / yii validation js to handle the active form fields correctly and separately. Read the wiki below to get a better way on how to handle the whole process.

It’s called tabular input. There is a gridview widget that does it (Tabular Input Form Widget). Here is also a wiki (handling tabluar input).

Thanks for the clear explanation. It’s all clear to me now! :slight_smile: Never new this was called tabular input. I will never forget that anymore.

Thank you for the help!

Glad to help. I hope you get it figured out

Sure did! Did not use the plugin, but handle it myself. Works excellent. Thank you!