Наследование: extends yii\base\Object
Пример #1
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);
     }
 }
 /**
  * @inheritdoc
  */
 protected function renderWidget($type, $name, $value, $options)
 {
     // Extend options in case of rendering embedded MultipleInput
     // We have to pass to the widget an original model and an attribute to be able get a first error from model
     // for embedded widget.
     if ($type === MultipleInput::className()) {
         $model = $this->context->model;
         // in case of embedding level 2 and more
         if (preg_match('/^([\\w\\.]+)(\\[.*)$/', $this->context->attribute, $matches)) {
             $search = sprintf('%s[%s]%s', $model->formName(), $matches[1], $matches[2]);
         } else {
             $search = sprintf('%s[%s]', $model->formName(), $this->context->attribute);
         }
         $replace = $this->context->attribute;
         $attribute = str_replace($search, $replace, $name);
         $options['model'] = $model;
         $options['attribute'] = $attribute;
         // Remember current name and mark the widget as embedded to prevent
         // generation of wrong prefix in case when column is associated with AR relation
         // @see https://github.com/unclead/yii2-multiple-input/issues/92
         $options['name'] = $name;
         $options['isEmbedded'] = true;
     }
     return parent::renderWidget($type, $name, $value, $options);
 }
Пример #3
0
 /**
  * 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;
     $error = '';
     if ($index !== null) {
         $error = $column->getFirstError($index);
         $hasError = !empty($error);
     }
     if ($column->enableError) {
         $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]);
 }