diff --git a/src/DynamicFormWidget.php b/src/DynamicFormWidget.php index f7c26f5..5a12cc4 100644 --- a/src/DynamicFormWidget.php +++ b/src/DynamicFormWidget.php @@ -68,7 +68,7 @@ class DynamicFormWidget extends \yii\base\Widget /** * @var string css class for primary key field. Must be added to input field */ - public $pkKeyCss = '.pk-id-field'; + public $pkKeyCss = 'pk-id-field'; /** * @var string */ @@ -221,7 +221,9 @@ public function registerAssets($view) $js .= "});\n"; $view->registerJs($js, $view::POS_READY); - $js = 'jQuery("#' . $this->formId . '").yiiDynamicForm(' . $this->_hashVar .');' . "\n"; + $js = 'jQuery("#' . $this->formId . '").on("afterInit", function(e) {' . "\n"; + $js .= ' jQuery("#' . $this->formId . '").yiiDynamicForm(' . $this->_hashVar .');' . "\n"; + $js .= "});\n"; $view->registerJs($js, $view::POS_LOAD); } diff --git a/src/assets/yii2-dynamic-form.js b/src/assets/yii2-dynamic-form.js index 5b47249..fd8530a 100644 --- a/src/assets/yii2-dynamic-form.js +++ b/src/assets/yii2-dynamic-form.js @@ -87,8 +87,17 @@ // remove "error/success" css class var yiiActiveFormData = $('#' + widgetOptions.formId).yiiActiveForm('data'); - $template.find('.' + yiiActiveFormData.settings.errorCssClass).removeClass(yiiActiveFormData.settings.errorCssClass); - $template.find('.' + yiiActiveFormData.settings.successCssClass).removeClass(yiiActiveFormData.settings.successCssClass); + + var $errorCssClass = "has-error"; var $successCssClass = "has-success"; // init default yii class + + // seek settings data only if object is not undefined. + if ( typeof yiiActiveFormData != 'undefined') { + $errorCssClass = yiiActiveFormData.settings.errorCssClass; + $successCssClass = yiiActiveFormData.settings.successCssClass; + } + + $template.find('.' + $errorCssClass).removeClass($errorCssClass); + $template.find('.' + $successCssClass).removeClass($successCssClass); return $template; };