/**
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if ($this->enableError && !$this->widget->model instanceof Model) {
         throw new InvalidConfigException('Property "enableError" available only when model is defined.');
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function setModel($model)
 {
     $currentModel = $this->getModel();
     // If model is null and current model is not empty it means that widget renders a template
     // In this case we have to unset all model attributes
     if ($model === null && $currentModel !== null) {
         foreach ($currentModel->attributes() as $attribute) {
             $currentModel->{$attribute} = null;
         }
     } else {
         parent::setModel($model);
     }
 }
 /**
  * Renders the cell content.
  *
  * @param BaseColumn $column
  * @param int|null $index
  * @return string
  */
 public function renderCellContent($column, $index)
 {
     $id = $column->getElementId($index);
     $name = $column->getElementName($index);
     $input = $column->renderInput($name, ['id' => $id]);
     if ($column->isHiddenInput()) {
         return $input;
     }
     $hasError = false;
     if ($column->enableError) {
         $error = $column->getFirstError($index);
         $hasError = !empty($error);
         $input .= "\n" . $column->renderError($error);
     }
     $wrapperOptions = ['class' => 'form-group field-' . $id];
     if ($hasError) {
         Html::addCssClass($wrapperOptions, 'has-error');
     }
     $input = Html::tag('div', $input, $wrapperOptions);
     return Html::tag('td', $input, ['class' => 'list-cell__' . $column->name]);
 }