I'm trying to use nested dynamic forms using this yii2 widget and following this guide but whenever I try to have a second dynamic form nested in the first form I get an error stating
TypeError
Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given
If I remove the the <?php DynamicFormWidget::begin([...]):?> and <?php DynamicFormWidget::end()?> the page loads (without the second dynamic form's functionality).
I here is the section of my view that deals with the nested dynamic forms
<?php
$form = ActiveForm::begin(['id'=> 'dynamic-form']);
?>
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper',
'widgetBody' => '.container-room-items',
'widgetItem' => '.room-item',
'limit' => 10,
'min' => 1,
'insertButton' => '.add-room',
'deleteButton' => '.remove-room',
'model' => $rooms[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
'description',
'price',
'room_capacity',
'area'
],
]); ?>
<table>
...
<td>
<?php foreach ($rooms as $indexRoom => $room): ?>
...
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_inner',
'widgetBody' => '.container-bed-items',
'widgetItem' => '.bed-item',
'limit' => 4,
'min' => 1,
'insertButton' => '.add-bed',
'deleteButton' => '.remove-bed',
'model' => $room_beds[$indexRoom][0],
'formId' => 'dynamic-form',
'formFields' => [
'bed_type_id',
'capacity'
],
]); ?>
<table>...</table>
<?php DynamicFormWidget::end(); //closing inner widget... errors happens on this line?>
<?php endforeach; ?>
</td>
</table>
<?php DynamicFormWidget::end(); ?>
</div>
Not sure what's missing. Would greatly appreciate any help with this, thanks.
You are missing html tags with classes configured in widget. Something like this:
Also, you need buttons for insert/delete with configured classes.