/** * Validates the display of correct attributes and buttons * at initialization based on mode * * @return void */ protected function validateDisplay() { $none = 'display:none'; if (count($this->model->getErrors()) > 0) { $this->mode = self::MODE_EDIT; } if ($this->mode === self::MODE_EDIT) { Html::addCssClass($this->container, 'kv-edit-mode'); Html::addCssStyle($this->viewAttributeContainer, $none); Html::addCssStyle($this->viewButtonsContainer, $none); } else { Html::addCssClass($this->container, 'kv-view-mode'); Html::addCssStyle($this->editAttributeContainer, $none); Html::addCssStyle($this->editButtonsContainer, $none); } }
/** * Renders each form attribute * * @param array $config the attribute config * * @return mixed * @throws \yii\base\InvalidConfigException */ protected function renderFormAttribute($config) { if (empty($config['attribute'])) { return ''; } $model = ArrayHelper::getValue($config, 'editModel', $this->model); if (!$model instanceof Model) { $model = $this->model; } $attr = ArrayHelper::getValue($config, 'updateAttr', $config['attribute']); $input = ArrayHelper::getValue($config, 'type', self::INPUT_TEXT); $fieldConfig = ArrayHelper::getValue($config, 'fieldConfig', []); $inputWidth = ArrayHelper::getValue($config, 'inputWidth', ''); $container = ArrayHelper::getValue($config, 'inputContainer', []); if ($inputWidth != '') { Html::addCssStyle($container, "width: {$inputWidth}"); // deprecated since v1.7.4 } $template = ArrayHelper::getValue($fieldConfig, 'template', "{input}\n{error}\n{hint}"); $row = Html::tag('div', $template, $container); if (static::hasGridCol($container)) { $row = '<div class="row">' . $row . '</div>'; } $fieldConfig['template'] = $row; if (substr($input, 0, 8) == "\\kartik\\") { Config::validateInputWidget($input, 'as an input widget for DetailView edit mode'); } elseif ($input !== self::INPUT_WIDGET && !in_array($input, self::$_inputsList)) { throw new InvalidConfigException("Invalid input type '{$input}' defined for the attribute '" . $config['attribute'] . "'."); } $options = ArrayHelper::getValue($config, 'options', []); $widgetOptions = ArrayHelper::getValue($config, 'widgetOptions', []); $class = ArrayHelper::remove($widgetOptions, 'class', ''); if (!empty($config['options'])) { $widgetOptions['options'] = $config['options']; } if (Config::isInputWidget($input)) { $class = $input; return $this->_form->field($model, $attr, $fieldConfig)->widget($class, $widgetOptions); } if ($input === self::INPUT_WIDGET) { if ($class == '') { throw new InvalidConfigException("Widget class not defined in 'widgetOptions' for {$input}'."); } return $this->_form->field($model, $attr, $fieldConfig)->widget($class, $widgetOptions); } if (in_array($input, self::$_dropDownInputs)) { $items = ArrayHelper::getValue($config, 'items', []); return $this->_form->field($model, $attr, $fieldConfig)->{$input}($items, $options); } if ($input == self::INPUT_HTML5_INPUT) { $inputType = ArrayHelper::getValue($config, 'inputType', self::INPUT_TEXT); return $this->_form->field($model, $attr, $fieldConfig)->{$input}($inputType, $options); } return $this->_form->field($model, $attr, $fieldConfig)->{$input}($options); }
/** * Validates the display of correct attributes and buttons * at initialization based on mode */ protected function validateDisplay() { $none = 'display:none'; if ($this->mode === self::MODE_VIEW) { Html::addCssStyle($this->editAttributeContainer, $none); Html::addCssStyle($this->editButtonsContainer, $none); } else { Html::addCssStyle($this->viewAttributeContainer, $none); Html::addCssStyle($this->viewButtonsContainer, $none); } }