Skip to content

Commit

Permalink
Update hint styling & code for old PHP ver fix #130 fix #131
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Oct 19, 2021
1 parent 64b83af commit 5210611
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Change Log: `yii2-widget-activeform`

**Date**: _under development_

- (enh #131): Enhance hint block styling.
- (enh #130): Support isset validation for older PHP versions.
- (enh #129): Enhance radioList and checkboxList styles.

## Version 1.6.0
Expand Down
15 changes: 4 additions & 11 deletions src/ActiveField.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ protected function createLayoutConfig($instanceConfig = [])
$layout = $form->type;
$bsVer = $form->getBsVer();
$config = [
'hintOptions' => ['tag' => 'div', 'class' => ['form-text', 'text-muted', 'small']],
'hintOptions' => ['tag' => 'div', 'class' => ['hint-block']],
'errorOptions' => ['tag' => 'div', 'class' => 'invalid-feedback'],
'inputOptions' => ['class' => 'form-control'],
'labelOptions' => ['class' => ['form-label']],
Expand All @@ -502,11 +502,7 @@ protected function createLayoutConfig($instanceConfig = [])
if ($bsVer === 4) {
$config['labelOptions'] = ['class' => []];
} elseif ($bsVer === 3) {
$config = [
'hintOptions' => ['tag' => 'p', 'class' => ['help-block']],
'errorOptions' => ['tag' => 'p', 'class' => 'help-block help-block-error'],
'inputOptions' => ['class' => 'form-control'],
];
$config['errorOptions'] = ['tag' => 'div', 'class' => 'help-block help-block-error'];
}
if ($layout === ActiveForm::TYPE_HORIZONTAL) {
$config['template'] = "{label}\n{beginWrapper}\n{input}\n{error}\n{hint}\n{endWrapper}";
Expand Down Expand Up @@ -665,9 +661,6 @@ public function hint($content, $options = [])

return $this;
}
if ($this->_isHintSpecial) {
Html::addCssClass($options, 'kv-hint-block');
}

return parent::hint($this->generateHint($content), $options);
}
Expand Down Expand Up @@ -946,7 +939,7 @@ public function widget($class, $config = [])
*/
public function staticInput($options = [])
{
$content = $this->staticValue ?? Html::getAttributeValue($this->model, $this->attribute);
$content = isset($this->staticValue) ? $this->staticValue : Html::getAttributeValue($this->model, $this->attribute);
$this->form->addCssClass($options, ActiveForm::BS_FORM_CONTROL_STATIC);
$this->parts['{input}'] = Html::tag('div', $content, $options);
$this->_isStatic = true;
Expand Down Expand Up @@ -1188,7 +1181,7 @@ protected function initDisability(&$options)
*/
protected function getConfigParam($param, $default = true)
{
return $this->$param ?? ArrayHelper::getValue($this->form->formConfig, $param, $default);
return isset($this->$param) ? $this->$param : ArrayHelper::getValue($this->form->formConfig, $param, $default);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ActiveForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,14 @@ protected function initForm()
if ($this->isHorizontal()) {
$css[] = 'kv-form-horizontal';
}
$formCss = 'kv-form-bs3';
if ($bsVer !== 3) {
$css[] = 'kv-form-bs4';
$formCss = 'kv-form-bs4';
if ($this->tooltipStyleFeedback) {
$css[] = 'tooltip-feedback';
}
}
$css[] = $formCss;
Html::addCssClass($this->options, $css);
}

Expand Down
5 changes: 5 additions & 0 deletions src/assets/css/activeform.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ label.disabled, label.readonly, .disabled label, .readonly label {
.kv-form-bs4 .has-error .invalid-feedback {
display: block;
}
.kv-form-bs3 .hint-block {
font-size: 12px;
margin-top: -5px;
color: #999;
}
.kv-form-bs4 .hint-block {
font-size: 0.75rem;
margin-top: 0.375rem;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/activeform.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5210611

Please sign in to comment.