Skip to content

Commit

Permalink
Fixed some bugs:
Browse files Browse the repository at this point in the history
  • Loading branch information
StitchUA committed Aug 16, 2021
1 parent 589cc5a commit aaaa56d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/DynamicFormWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 11 additions & 2 deletions src/assets/yii2-dynamic-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit aaaa56d

Please sign in to comment.