-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathEBootstrapActiveForm.php
More file actions
229 lines (202 loc) · 5.22 KB
/
Copy pathEBootstrapActiveForm.php
File metadata and controls
229 lines (202 loc) · 5.22 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/*
* Wrapper class for CActiveForm
* Apply bootstrap style to the form
*
* @author Tim Helfensdörfer <tim@visualappeal.de>
* @version 0.3.0
* @package bootstrap.yiiwidgets
*/
class EBootstrapActiveForm extends CActiveForm {
/*
* Display a horizontal form
*
* Default: false
*/
public $horizontal = false;
/*
* Error message css class
*
* Default: help-inline
*/
public $errorMessageCssClass = 'help-inline';
/*
* Init the widget
*/
public function init() {
if ($this->horizontal)
EBootstrap::mergeClass($this->htmlOptions, array('form-horizontal'));
parent::init();
}
/*
* Execute the widget
*/
public function run() {
parent::run();
}
/*
* Begins a control group
*
* Into the control group belongs the label, the input and the error
*
* @param CModel $model The model
* @param string $attribute The attribute
*/
public function beginControlGroup($model, $attribute) {
$option = array();
$option['class'] = 'control-group';
$error = $model->getError($attribute);
if (!empty($error))
EBootstrap::mergeClass($option, array('error'));
echo EBootstrap::openTag('div', array('class' => $option['class']));
}
/*
* End of the control group
*/
public function endControlGroup() {
echo EBootstrap::closeTag('div');
}
/*
* Beginning of the controls (inputs)
*/
public function beginControls() {
echo EBootstrap::openTag('div', array('class' => 'controls'));
}
/*
* End of the controls
*/
public function endControls() {
echo EBootstrap::closeTag('div');
}
/*
* Beginning of the form actions
*
* Into the action sections belong all buttons like the submit or abort button
*/
public function beginActions() {
echo EBootstrap::openTag('div', array('class' => 'form-actions'));
}
/*
* End form actions
*/
public function endActions() {
echo EBootstrap::closeTag('div');
}
/*
* Error summary
*
* Apply bootstrap style to the error summary
*
* @param CModel $model
* @param string $header
* @param string $footer
* @param array $htmlOptions
*/
public function errorSummary($model,$header=null,$footer=null,$htmlOptions=array()) {
$content='';
if(!is_array($model))
$model=array($model);
if(isset($htmlOptions['firstError']))
{
$firstError=$htmlOptions['firstError'];
unset($htmlOptions['firstError']);
}
else
$firstError=false;
foreach($model as $m)
{
foreach($m->getErrors() as $errors)
{
foreach($errors as $error)
{
if($error!='')
$content.="<li>$error</li>\n";
if($firstError)
break;
}
}
}
if($content!=='')
{
if($header===null)
$header=Yii::t('yii','Please fix the following input errors:');
$header = EBootstrap::tag('h4', array('class' => 'alert-heading'), $header)."\n";
if(!isset($htmlOptions['class']))
$htmlOptions['class']=EBootstrap::$errorSummaryCss;
EBootstrap::mergeClass($htmlOptions, array('alert', 'alert-error', 'alert-block'));
return EBootstrap::tag('div',$htmlOptions,$header."\n<ul>\n$content</ul>".$footer);
}
else
return '';
}
/*
* Returns a HTML label
*
* @param CModel $model The model
* @param string $attribute The attribute
* @param array $htmlOptions
*/
public function label($model,$attribute,$htmlOptions=array()) {
if ($this->horizontal)
EBootstrap::mergeClass($htmlOptions, array('control-label'));
return EBootstrap::activeLabel($model,$attribute,$htmlOptions);
}
/*
* Returns an advanced HTML label
*
* @param CModel $model The model
* @param string $attribute The attribute
* @param array $htmlOptions
*/
public function labelEx($model,$attribute,$htmlOptions=array()) {
if ($this->horizontal)
EBootstrap::mergeClass($htmlOptions, array('control-label'));
return EBootstrap::activeLabelEx($model,$attribute,$htmlOptions);
}
/*
* Render an input field with a prepended text or icon
*
* @param CModel $model The model
* @param string $attribute The attribute
* @param string $prepend The text or icon to prepend
* @param array $htmlOptions
*/
public function textFieldPrepend($model,$attribute,$prepend,$htmlOptions=array()) {
return EBootstrap::activeTextFieldPrepend($model, $attribute, $prepend, $htmlOptions);
}
/*
* Render an input field with a append text or icon
*
* @param CModel $model The model
* @param string $attribute The attribute
* @param string $append The text or icon to append
* @param array $htmlOptions
*/
public function textFieldAppend($model,$attribute,$append,$htmlOptions=array()) {
return EBootstrap::activeTextFieldAppend($model, $attribute, $append, $htmlOptions);
}
/*
* Returns a help block
*
* Help block can be used to improve the usabilty of a form
*
* @param string $help Help message
*/
public function helpBlock($help) {
$html = EBootstrap::openTag('p', array('class' => 'help-block'));
$html .= $help;
$html .= EBootstrap::closeTag('p');
return $html;
}
/*
* Render a submit buttom
*
* @param string $label Label
* @param array $htmlOptions
*/
public function submitButton($label, $htmlOptions = array()) {
EBootstrap::mergeClass($htmlOptions, array('btn', 'btn-primary'));
return EBootstrap::submitButton($label, $htmlOptions);
}
}
?>