forked from worstinme/yii2-uikit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveForm.php
122 lines (95 loc) · 3.73 KB
/
ActiveForm.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace worstinme\uikit;
use Yii;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\base\InvalidConfigException;
use yii\widgets\ActiveFormAsset;
class ActiveForm extends \yii\widgets\ActiveForm
{
public $fieldClass = 'worstinme\uikit\ActiveField';
/**
* @var string the form layout. Either 'default', 'horizontal' or 'stacked'.
*/
public $layout = 'default';
/**
* @var string the form field size. Either 'large', 'small'.
*/
public $field_size = false;
/**
* @var string the form field width. Either 'full','large','medium', 'small', 'mini'.
*/
public $field_width = false;
public $inputOptions = [];
public $scripts_inform = false;
/**
* @inheritdoc
*/
public function init()
{
if (!in_array($this->layout, ['default', 'horizontal', 'stacked'])) {
throw new InvalidConfigException('Invalid layout type: ' . $this->layout);
}
Html::addCssClass($this->options, 'uk-form');
if ($this->layout !== 'default') {
Html::addCssClass($this->options, 'uk-form-' . $this->layout);
}
if ($this->field_size) {
if (!in_array($this->field_size, ['large', 'small'])) {
throw new InvalidConfigException('Invalid size: ' . $this->layout.'. It must be large or small');
}
Html::addCssClass($this->inputOptions, 'uk-form-' . $this->field_size);
}
if ($this->field_size) {
if (!in_array($this->field_size, ['large', 'small'])) {
throw new InvalidConfigException('Invalid size: ' . $this->layout.'. It must be large & small');
}
else {
Html::addCssClass($this->inputOptions, 'uk-form-' . $this->field_size);
}
}
if ($this->field_width) {
if (!in_array($this->field_width, ['full','large','medium', 'small', 'mini'])) {
throw new InvalidConfigException('Invalid width: ' . $this->field_width.'. It must be full, large, medium, small or mini');
}
else {
Html::addCssClass($this->inputOptions, $this->field_width != 'full' ? 'uk-form-width-' . $this->field_width : 'uk-width-1-1');
}
}
if (isset($this->inputOptions['class'])) {
$this->fieldConfig['inputOptions'] = ['class' => $this->inputOptions['class']];
}
parent::init();
}
/* public function run()
{
if (!empty($this->_fields)) {
throw new InvalidCallException('Each beginField() should have a matching endField() call.');
}
if ($this->enableClientScript) {
$id = $this->options['id'];
$options = Json::htmlEncode($this->getClientOptions());
$attributes = Json::htmlEncode($this->attributes);
$view = $this->getView();
ActiveFormAsset::register($view);
if ($this->enableClientValidation) {
if ($this->scripts_inform) {
echo "<script type=\"text/javascript\">jQuery(document).ready(function () { jQuery('#$id').yiiActiveForm($attributes, $options);});</script>";
}
else {
$view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");
}
}
}
echo Html::endForm();
} */
public function field($model, $attribute, $options = [])
{
return parent::field($model, $attribute, $options);
}
}