* @copyright (c), Thread */ class ActiveForm extends \yii\bootstrap\ActiveForm { public $fieldClass = ActiveField::class; // public $enableClientValidation = true; public $enableAjaxValidation = true; public $validateOnSubmit = true; public $enableClientScript = true; public $validationUrl = 'validation'; /** * */ public function init() { $this->action = Url::current(); parent::init(); $this->validationUrl = Url::toRoute($this->validationUrl) . '?id=' . ((isset($_GET['id'])) ? $_GET['id'] : 0); $view = $this->getView(); $view->registerJs($this->setSubmit()); } /** * @return JsExpression */ public function setSubmit() { return new JsExpression('$("#' . $this->getId() . ' button[type=submit]").on( "click", function() { var formId = "#' . $this->getId() . '"; var url = "' . $this->validationUrl . '"; var is_valid = false; if(url.length){ var dataForm = $(formId).serialize(); $.post(url, dataForm, function(data){ var obj = data; var classExtError = ".help-block-error"; console.log(obj); if(data.length == 0){ is_valid = true; $(formId).submit(); } $("#' . $this->getId() . '").find(".has-error").removeClass("has-error"); $("#' . $this->getId() . '").find(classExtError).html(""); for(attr in obj){ $("#"+attr).parents(".form-group").addClass("has-error"); $("#"+attr).parents(".form-group").find(classExtError).html(obj[attr]); } }); } return is_valid; });'); } /** * @param array $models * @param null $attributes * @return array */ public static function validateMultiple($models, $attributes = null) { $result = []; /** @var Model $model */ foreach ($models as $model) { $model->validate($attributes); foreach ($model->getErrors() as $attribute => $errors) $result[Html::getInputId($model, $attribute)] = $errors; } return $result; } /** * @param $model * @param $attribute * @param array $options * @return mixed */ public function text_line($model, $attribute, $options = []) { return $this->field($model, $attribute, $options)->placeholder(Html::encode($model->getAttributeLabel($attribute)))->textInput(['maxlength' => true]); } /** * @param $model * @param $attribute * @param array $options * @return mixed */ public function text_line_lang($model, $attribute, $options = []) { return $this->text_line($model, $attribute, $options)->sign_lang(); } /** * @param $model * @param $attribute * @param array $options * @return mixed */ public function text($model, $attribute, $options = []) { return $this->field($model, $attribute)->placeholder(Html::encode($model->getAttributeLabel($attribute)))->textarea($options); } /** * @param $model * @param $attribute * @param array $options * @return mixed */ public function text_lang($model, $attribute, $options = []) { if (!isset($options['style'])) { $options['style'] = ''; } $options['style'] .= ';resize: none;'; return $this->field($model, $attribute)->placeholder(Html::encode($model->getAttributeLabel($attribute)))->sign_lang()->textarea($options); } /** * @param $model * @param $attribute * @param array $options * @return mixed */ public function text_editor($model, $attribute, $options = []) { return $this->field($model, $attribute, $options)->editor(); } /** * @param $model * @param $attribute * @param array $options * @param string $thema * @return mixed */ public function text_editor_lang($model, $attribute, $options = [], $thema = 'full') { $template = [ 'template' => '