du229908 2016-12-08 10:17
浏览 59

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

I am having problem with multiple dynamic forms in a single form.

When I press add on the second dynamic form it adds the 1st dynamic form.

What are the changes I need to make in the form?

  • 写回答

1条回答 默认 最新

  • doucitan2544 2018-04-15 20:37
    关注

    Only now I'm using this class.

    If you have 2 form you have to change few items in second DynamicFormWidget.

    First form:

    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',
        ],
    ]);
    

    and

    <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>
    

    Second form:

    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
        ],
    ]);
    

    and

    <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>
    
    评论

报告相同问题?