This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm.php
46 lines (38 loc) · 1.56 KB
/
Form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace ext\activedocument;
use CHtml, Yii;
/**
* @todo Make this more dynamic, so that other form classes could be specified for Form to extend from
*/
Yii::registerAutoloader(function($class) {
if (strcasecmp($class, 'ext\activedocument\FakeInheritForm') === 0) {
if (Yii::getPathOfAlias('bootstrap.widgets.BootActiveForm')
&& Yii::import('bootstrap.widgets.BootActiveForm', true) && class_exists('BootActiveForm')
) {
class_alias('BootActiveForm', 'ext\activedocument\FakeInheritForm');
} else {
class_alias('CActiveForm', 'ext\activedocument\FakeInheritForm');
}
}
});
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedNamespaceInspection */
class Form extends \ext\activedocument\FakeInheritForm {
public function error($model, $attribute, $htmlOptions = array(), $enableAjaxValidation = true, $enableClientValidation = true) {
/**
* Determine input id
*/
$id = CHtml::activeId($model, $attribute);
$inputID = isset($htmlOptions['inputID']) ? $htmlOptions['inputID'] : $id;
/**
* Let widget process as normal
*/
$html = parent::error($model, $attribute, $htmlOptions, $enableAjaxValidation, $enableClientValidation);
/**
* If inputid exists, update status field as necessary
*/
if ($model instanceof Document && !$model->isNewRecord && isset($this->attributes[$inputID]))
$this->attributes[$inputID]['status'] = 1;
return $html;
}
}