wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

class DynamicFormWidget (add a click handler for the clone button)

xr0m3oz opened this issue · comments

If you make the nesting structure of one to another. That is 2 buttons to add a line. When you click on the second button. Added 2 lines instead of 1st. Click triggered 2 times in a row.

But it works fine when you click on the first add button. And it adds 1 line as well.

//need add
$js .= "    e.stopImmediatePropagation();\n";

//to
         // add a click handler for the clone button
        $js = 'jQuery("#' . $this->formId . '").on("click", "' . $this->insertButton . '", function(e) {'. "\n";
        $js .= "    e.preventDefault();\n";
        $js .= "    e.stopImmediatePropagation();\n"; // ITS!
        $js .= '    jQuery(".' .  $this->widgetContainer . '").triggerHandler("beforeInsert", [jQuery(this)]);' . "\n";
        $js .= '    jQuery(".' .  $this->widgetContainer . '").yiiDynamicForm("addItem", '. $this->_hashVar . ", e, jQuery(this));\n";
        $js .= "});\n";
        $view->registerJs($js, $view::POS_READY);

widget