yii2多动态形式wbraganca(需要区分的类是什么)

时间:2016-12-08 10:17:33

标签: php yii2 dynamic-forms

我在单个表单中遇到多个动态表单的问题。

当我在第二个动态表单上按add时,它会添加第一个动态表单。

我需要在表单中进行哪些更改?

1 个答案:

答案 0 :(得分:0)

现在我才使用这个课程。

如果您有2个表单,则必须在第二个DynamicFormWidget中更改几个项目。

第一种形式:

DynamicFormWidget::begin([
    'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
    'widgetBody' => '.container-items', // required: css class selector
    'widgetItem' => '.item', // required: css class
    'limit' => 5, // the maximum times, an element can be cloned (default 999)
    'min' => 0, // 0 or 1 (default 1)
    'insertButton' => '.add-item', // css class
    'deleteButton' => '.remove-item', // css class
    'model' => $user[0],
    'formId' => 'dynamic-form',
    'formFields' => [
        'name',
        'email',
    ],
]);

<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>

第二种形式:

DynamicFormWidget::begin([
    'widgetContainer' => 'dynamicform_wrapper',
    'widgetBody' => '.container-items',
    'widgetItem' => '.item2', // CHANGED
    'limit' => 5, 
    'min' => 0,
    'insertButton' => '.add-item2', // CHANGED
    'deleteButton' => '.remove-item2', // CHANGED
    'model' => $car[0], // CHANGED
    'formId' => 'dynamic-form',
    'formFields' => [
        'color', // CHANGED
        'type', // CHANGED
    ],
]);

<div class="pull-right">
<button type="button" class="add-item2 btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item2 btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>