/**
  * Returns input container class for any given attribute, depending on validation conditions.
  * @param CModel $model the data model
  * @param string $attribute the attribute name
  */
 public function fieldClass($model, $attribute)
 {
     $class = 'control-group';
     if ($model->getError($attribute)) {
         $class .= ' error';
     }
     return $class;
 }
Exemple #2
0
 /**
  * get error info from model
  * 
  * @param CModel $model
  * @return string
  * @see CModel
  */
 public static function errorModelSummery($model, $attribute = null)
 {
     if (is_null($attribute)) {
         return self::errorSummery($model->getErrors());
     } else {
         $aryError = $model->getError($attribute, false);
         return empty($aryError) ? '' : self::errorSummery(array($aryError));
     }
 }
Exemple #3
0
 /**
  * Generates a custom (pre-rendered) active form control group.
  * @param string $input the rendered input.
  * @param CModel $model the data model.
  * @param string $attribute the attribute.
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated control group.
  */
 public static function customActiveControlGroup($input, $model, $attribute, $htmlOptions = array())
 {
     // modificado segun lo visto en el foro de yii
     $htmlOptions['input'] = $input;
     if ($model->hasErrors($attribute)) {
         $htmlOptions['color'] = TbHtml::INPUT_COLOR_ERROR;
         $htmlOptions['help'] = $model->getError($attribute);
         $htmlOptions['helpOptions'] = array('type' => TbHtml::HELP_TYPE_BLOCK);
     }
     return self::activeControlGroup(self::INPUT_TYPE_CUSTOM, $model, $attribute, $htmlOptions);
 }
Exemple #4
0
 /**
  * Displays the first validation error for a model attribute.
  * @param CModel $model the data model
  * @param string $attribute the attribute name
  * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
  * This parameter has been available since version 1.0.7.
  * @return string the error display. Empty if no errors are found.
  * @see CModel::getErrors
  * @see errorMessageCss
  */
 public static function error($model, $attribute, $htmlOptions = array())
 {
     $error = $model->getError($attribute);
     if ($error != '') {
         if (!isset($htmlOptions['class'])) {
             $htmlOptions['class'] = self::$errorMessageCss;
         }
         return self::tag('div', $htmlOptions, $error);
     } else {
         return '';
     }
 }
 /**
  * Begins a form group.
  *
  * Into the form group belongs the label, the input and the error.
  *
  * @param CModel $model The model
  * @param string $attribute The attribute
  *
  * @access public
  * @return string
  */
 public function beginControlGroup($model, $attribute, $options = array())
 {
     $option = array();
     $option['class'] = 'form-group';
     $error = $model->getError($attribute);
     if (!empty($error)) {
         EBootstrap::mergeClass($option, array('has-error'));
     }
     EBootstrap::mergeClass($options, $option);
     return EBootstrap::openTag('div', $options);
 }
 /**
  * @param string $method the CActiveForm method name, e.g. textField, dropDownList, etc.
  * @param CModel $model the form model
  * @param string $attribute the attribute name
  * @param bool|array $listOptions list options or false if none
  * @param array $options group options
  * @return string the rendered form group
  */
 protected function renderGroup($method, $model, $attribute, $listOptions, $options)
 {
     if (isset($options['label']) && $options['label'] === false) {
         $beginLabel = $endLabel = $labelTitle = $label = '';
     } else {
         $beginLabel = \CHtml::openTag('label', $options['labelOptions']);
         $endLabel = \CHtml::closeTag('label');
         $labelTitle = isset($options['label']) ? $options['label'] : $model->getAttributeLabel($attribute);
         $label = \CHtml::tag('label', $options['labelOptions'], $labelTitle);
     }
     $beginWrapper = \CHtml::openTag($options['wrapperTag'], $options['wrapperOptions']);
     $endWrapper = \CHtml::closeTag($options['wrapperTag']);
     if ($model->hasErrors($attribute) && $options['enableErrorBlock']) {
         $error = \CHtml::tag($options['errorTag'], $options['errorOptions'], $model->getError($attribute));
         $options['groupOptions']['class'] = isset($options['groupOptions']['class']) ? $options['groupOptions']['class'] . ' has-error' : 'has-error';
     } else {
         $error = '';
     }
     $help = isset($options['helpText']) ? \CHtml::tag($options['helpTag'], $options['helpOptions'], $options['helpText']) : '';
     if ($this->layout === 'inline' && !isset($options['inputOptions']['placeholder'])) {
         $options['inputOptions']['placeholder'] = $labelTitle;
     }
     if ($listOptions) {
         $input = parent::$method($model, $attribute, $listOptions, $options['inputOptions']);
     } else {
         $input = parent::$method($model, $attribute, $options['inputOptions']);
     }
     if (isset($options['inputTemplate'])) {
         $input = strtr($options['inputTemplate'], array('{input}' => $input));
     }
     $content = strtr($options['template'], array('{label}' => $label, '{beginLabel}' => $beginLabel, '{labelTitle}' => $labelTitle, '{endLabel}' => $endLabel, '{beginWrapper}' => $beginWrapper, '{endWrapper}' => $endWrapper, '{input}' => $input, '{error}' => $error, '{help}' => $help));
     return \CHtml::tag($options['groupTag'], $options['groupOptions'], $content);
 }