wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
436 stars 438 forks source link

Issue with empty array #153

Open ferllings opened 8 years ago

ferllings commented 8 years ago

Hello,

When my initial array is empty, (because my 'min' config is 0) I receive this error:

Argument 1 passed to DOMDocument::importNode() must be an instance of DOMNode, null given

  1. in /app/vendor/wbraganca/yii2-dynamicform/src/DynamicFormWidget.php at line 234 $document->appendChild($document->importNode($results->first()->getNode(0), true));
dmytroraschepkin commented 8 years ago

I guess you can render an empty element always. You can then remove it from page after widget loading (e.g. some hack like timeout after document load etc.) which is not very pretty but may help you to resolve your issue.

As you can see from the code $results->first() - widget is using first element from the list as the template for all new items.

I have the same issue and I was not able to find any workaround. Anyway I'm OK with rendering empty element always.