/** * Renders the cell content. * * @param string $value * @param int|null $index * @return string * @throws InvalidConfigException */ public function renderCellContent($value, $index) { $type = $this->type; $name = $this->widget->getElementName($this->name, $index); $options = $this->options; $options['id'] = $this->widget->getElementId($this->name, $index); Html::addCssClass($options, 'form-control'); switch ($this->type) { case self::TYPE_HIDDEN_INPUT: $input = Html::hiddenInput($name, $value, $options); break; case self::TYPE_DROPDOWN: case self::TYPE_LISTBOX: case self::TYPE_CHECKBOX_LIST: case self::TYPE_RADIO_LIST: $input = Html::$type($name, $value, $this->items, $options); break; case self::TYPE_STATIC: $input = Html::tag('p', $value, ['class' => 'form-control-static']); break; default: if (method_exists('yii\\helpers\\Html', $type)) { $input = Html::$type($name, $value, $options); } elseif (class_exists($type) && method_exists($type, 'widget')) { $input = $type::widget(array_merge($options, ['name' => $name, 'value' => $value])); } else { throw new InvalidConfigException("Invalid column type '{$type}'"); } } if ($this->isHiddenInput()) { return $input; } $input = Html::tag('div', $input, ['class' => 'form-group field-' . $options['id']]); return Html::tag('td', $input, ['class' => 'list-cell__' . $this->name]); }
/** * Renders the cell content. * * @param string $value * @param int|null $index * @return string * @throws InvalidConfigException */ public function renderCellContent($value, $index) { $name = $this->widget->getElementName($this->name, $index); $options = $this->options; $options['id'] = $this->widget->getElementId($this->name, $index); $input = $this->renderInput($name, $value, $options); if ($this->isHiddenInput()) { return $input; } $hasError = false; if ($this->enableError) { $attribute = $this->widget->attribute . $this->widget->getElementName($this->name, $index, false); $error = $this->widget->model->getFirstError($attribute); $hasError = !empty($error); $input .= "\n" . $this->renderError($error); } $wrapperOptions = ['class' => 'form-group field-' . $options['id']]; if ($hasError) { Html::addCssClass($wrapperOptions, 'has-error'); } $input = Html::tag('div', $input, $wrapperOptions); return Html::tag('td', $input, ['class' => 'list-cell__' . $this->name]); }