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

$toclone.clone is not a function #104

Open davidsoutoc opened 8 years ago

davidsoutoc commented 8 years ago

Hi,

I have a problem with this. I didn't get clone the elements. On console I obtain this error:

Uncaught TypeError: $toclone.clone is not a function on yii2-dynamic-form.js:120

I have defined correctly the jquery library, the other stuff on my projects with jquery works fine. If I put a console.log before the error line and I obtain the variable $toclone with the content of de div that I want clone and it looks ok.

If I added put this on the yii2-dynamic-form.js clone the div correctly but the original line continues with the error: var obj = $("div.item.panel.panel-default").eq(0).clone(); $("div.container-items").append(obj);

I don't understand what is the error.

Thanks for the help.

ShatalovViktor commented 8 years ago

Hi! I have this problem too. I just forgot to write ActiveForm::end();. Meybe it help you

ChristopheBrun commented 7 years ago

I also ran into this problem. console.log($toclone) showed that the variable was a string containing HTML code of the nested form to duplicate. Of course, clone() is not a function of the String class.

I fixed the bug by wrapping $toclone into a jQuery object :

        $toclone = $(widgetOptions.template);

Unfortunately, I had to modify the yii2-dynamic-form.js file of the extension for I don't know how to overload these assets in my application code.

dogrocker commented 7 years ago

I'd ran to this problem by update to dev-master.

richardoctoey commented 7 years ago

@ChristopheBrun it's late, but for other who experiencing this:

  1. copy paste yii2-dynamic-form.js into web/js
  2. replace the code as @ChristopheBrun solution
  3. add this to config. after that clear the asset, you should good to go
    'components'=>[
    ..
    'assetManager' => [
            'bundles' => [
                'wbraganca\dynamicform\DynamicFormAsset' => [
                    'sourcePath' => '@app/web/js',
                    'js' => [
                        'yii2-dynamic-form.js'
                    ],
                ],
            ],
        ],
    ]
dfuse-dev commented 6 years ago

same here. @richardoctoey solution worked for me

Nik1192 commented 6 years ago

yii2-dynamic-form.js:119 Uncaught TypeError: $toclone.clone is not a function at _addItem (yii2-dynamic-form.js:119) at jQuery.fn.init.addItem (yii2-dynamic-form.js:42) at jQuery.fn.init.$.fn.yiiDynamicForm (yii2-dynamic-form.js:17) at HTMLButtonElement. (index.php?r=po%2Fcreate:839) at HTMLFormElement.dispatch (jquery.js:5206) at HTMLFormElement.elemData.handle (jquery.js:5014)

mastershaig commented 6 years ago

Same issue as @Nik1192, anyone fixed ?

dezhavuu commented 5 years ago

the problem is exist yet and the solution from @ChristopheBrun is helpful.