17 abstract class TbInput extends CInputWidget
143 if (!isset($this->form)) {
144 throw new CException(__CLASS__ .
': Failed to initialize widget! Form is not set.');
147 if (!isset($this->model)) {
148 throw new CException(__CLASS__ .
': Failed to initialize widget! Model is not set.');
151 if (!isset($this->type)) {
152 throw new CException(__CLASS__ .
': Failed to initialize widget! Input type is not set.');
156 if ($this->type === self::TYPE_UNEDITABLE) {
157 if (isset($this->htmlOptions[
'class'])) {
158 $this->htmlOptions[
'class'] .=
' uneditable-input';
160 $this->htmlOptions[
'class'] =
'uneditable-input';
174 if (isset($this->htmlOptions[
'label'])) {
175 $this->label = $this->htmlOptions[
'label'];
176 unset($this->htmlOptions[
'label']);
179 if (isset($this->htmlOptions[
'prepend'])) {
180 $this->prependText = $this->htmlOptions[
'prepend'];
181 unset($this->htmlOptions[
'prepend']);
184 if (isset($this->htmlOptions[
'append'])) {
185 $this->appendText = $this->htmlOptions[
'append'];
186 unset($this->htmlOptions[
'append']);
189 if (isset($this->htmlOptions[
'hint'])) {
190 $this->hintText = $this->htmlOptions[
'hint'];
191 unset($this->htmlOptions[
'hint']);
194 if (isset($this->htmlOptions[
'labelOptions'])) {
195 $this->labelOptions = $this->htmlOptions[
'labelOptions'];
196 unset($this->htmlOptions[
'labelOptions']);
199 if (isset($this->htmlOptions[
'prependOptions'])) {
200 $this->prependOptions = $this->htmlOptions[
'prependOptions'];
201 unset($this->htmlOptions[
'prependOptions']);
204 if (isset($this->htmlOptions[
'appendOptions'])) {
205 $this->appendOptions = $this->htmlOptions[
'appendOptions'];
206 unset($this->htmlOptions[
'appendOptions']);
209 if (isset($this->htmlOptions[
'hintOptions'])) {
210 $this->hintOptions = $this->htmlOptions[
'hintOptions'];
211 unset($this->htmlOptions[
'hintOptions']);
214 if (isset($this->htmlOptions[
'errorOptions'])) {
215 $this->errorOptions = $this->htmlOptions[
'errorOptions'];
216 if (isset($this->htmlOptions[
'errorOptions'][
'enableAjaxValidation'])) {
217 $this->enableAjaxValidation = (boolean)$this->htmlOptions[
'errorOptions'][
'enableAjaxValidation'];
220 if (isset($this->htmlOptions[
'errorOptions'][
'enableClientValidation'])) {
221 $this->enableClientValidation = (boolean)$this->htmlOptions[
'errorOptions'][
'enableClientValidation'];
223 unset($this->htmlOptions[
'errorOptions']);
226 if (isset($this->htmlOptions[
'captchaOptions'])) {
227 $this->captchaOptions = $this->htmlOptions[
'captchaOptions'];
228 unset($this->htmlOptions[
'captchaOptions']);
241 switch ($this->type) {
242 case self::TYPE_CHECKBOX:
246 case self::TYPE_CHECKBOXLIST:
250 case self::TYPE_CHECKBOXLIST_INLINE:
254 case self::TYPE_CHECKBOXGROUPSLIST:
258 case self::TYPE_DROPDOWN:
262 case self::TYPE_FILE:
266 case self::TYPE_PASSWORD:
270 case self::TYPE_PASSFIELD:
274 case self::TYPE_RADIO:
278 case self::TYPE_RADIOLIST:
282 case self::TYPE_RADIOLIST_INLINE:
286 case self::TYPE_RADIOBUTTONGROUPSLIST:
290 case self::TYPE_TEXTAREA:
295 case self::TYPE_TEXT:
299 case self::TYPE_MASKEDTEXT:
303 case self::TYPE_CAPTCHA:
307 case self::TYPE_UNEDITABLE:
311 case self::TYPE_DATEPICKER:
315 case self::TYPE_DATETIMEPICKER:
319 case self::TYPE_REDACTOR:
323 case self::TYPE_MARKDOWNEDITOR:
327 case self::TYPE_HTML5EDITOR:
331 case self::TYPE_DATERANGEPICKER:
335 case self::TYPE_TOGGLEBUTTON:
339 case self::TYPE_COLORPICKER:
343 case self::TYPE_CKEDITOR:
347 case self::TYPE_TIMEPICKER:
351 case self::TYPE_SELECT2:
355 case self::TYPE_TYPEAHEAD:
359 case self::TYPE_NUMBER:
363 case self::TYPE_CUSTOM:
368 throw new CException(__CLASS__ .
': Failed to run widget! Type is invalid.');
381 if ($this->label !==
false && !in_array($this->type, array(
'checkbox',
'radio')) && $this->hasModel()) {
382 return $this->form->labelEx($this->model, $this->attribute, $this->labelOptions);
383 }
else if ($this->label !== null) {
402 if (isset($htmlOptions[
'class'])) {
403 $htmlOptions[
'class'] .=
' add-on';
405 $htmlOptions[
'class'] =
'add-on';
410 if (isset($this->prependText)) {
411 if (isset($htmlOptions[
'isRaw']) && $htmlOptions[
'isRaw']) {
414 echo CHtml::tag(
'span', $htmlOptions, $this->prependText);
418 return ob_get_clean();
436 if (isset($htmlOptions[
'class'])) {
437 $htmlOptions[
'class'] .=
' add-on';
439 $htmlOptions[
'class'] =
'add-on';
443 if (isset($this->appendText)) {
444 if (isset($htmlOptions[
'isRaw']) && $htmlOptions[
'isRaw']) {
447 echo CHtml::tag(
'span', $htmlOptions, $this->appendText);
452 return ob_get_clean();
469 return isset($this->htmlOptions[
'id'])
470 ? $this->htmlOptions[
'id']
471 : CHtml::getIdByName(CHtml::resolveName($this->model, $attribute));
483 return $this->form->error(
487 $this->enableAjaxValidation,
488 $this->enableClientValidation
501 if (isset($this->hintText)) {
504 if (isset($htmlOptions[
'class'])) {
505 $htmlOptions[
'class'] .=
' help-block';
507 $htmlOptions[
'class'] =
'help-block';
510 return CHtml::tag(
'p', $htmlOptions, $this->hintText);
525 return $this->model->hasErrors($this->attribute) ? CHtml::$errorCss :
'';
538 if (isset($this->prependText)) {
539 $classes[] =
'input-prepend';
541 if (isset($this->appendText)) {
542 $classes[] =
'input-append';
545 return implode(
' ', $classes);
557 return isset($this->prependText) || isset($this->appendText);
568 abstract protected function checkBox();
698 abstract protected function textArea();
728 abstract protected function captcha();
788 abstract protected function ckEditor();
878 case self::TYPE_CHECKBOX:
879 $method =
'checkBox';
881 case self::TYPE_RADIO:
882 $method =
'radioButton';
885 throw new CException(
'This method can be used with only selectable control', E_USER_ERROR);
888 $control = $this->form->{$method}($this->model, $this->attribute, $this->htmlOptions);
891 $hasHiddenField = (array_key_exists(
'uncheckValue', $this->htmlOptions) && $this->htmlOptions[
'uncheckValue'] === null)
895 if ($hasHiddenField && preg_match(
'/<input .*?type="hidden".*?\/>/', $control, $matches))
897 $hidden = $matches[0];
898 $control = str_replace($hidden,
'', $control);
901 return array($hidden, $control);