Skip to content

Commit 12e82f6

Browse files
committed
Updates to release v1.5.5
1 parent 9460f27 commit 12e82f6

File tree

10 files changed

+76
-40
lines changed

10 files changed

+76
-40
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Licensing
116116
---------
117117

118118
It should also be made clear that **all code contributed to yii2-widget-activeform** must be
119-
licensable under the [BSD-3 license][licensing]. Code that cannot be released
119+
licensable under the [BSD-3-Clause license][licensing]. Code that cannot be released
120120
under this license **cannot be accepted** into the project.
121121

122122
[issue-search]: https://github.com/kartik-v/yii2-widget-activeform/search?q=&type=Issues

CHANGE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Change Log: `yii2-widget-activeform`
22
====================================
33

4+
## Version 1.5.5
5+
6+
**Date**: 26-Sep-2018
7+
8+
- New `ActiveForm` methods `isHorizontal`, `isInline`, `isVertical` for easy layout detection.
9+
- Label styling enhancements.
10+
411
## Version 1.5.4
512

613
**Date**: 22-Sep-2018

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ echo $form->field($model, 'amount_paid', [
123123
echo $form->field($model, 'phone', [
124124
'addon' => [
125125
'prepend' => [
126-
'content' => '<i class="glyphicon glyphicon-phone"></i>'
126+
'content' => '<i class="fas fa-phone"></i>'
127127
]
128128
]
129129
]);

src/ActiveField.php

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.5.4
7+
* @version 1.5.5
88
*/
99

1010
namespace kartik\form;
@@ -123,6 +123,11 @@ class ActiveField extends YiiActiveField
123123
*/
124124
public $renderEmptyWrapper = false;
125125

126+
/**
127+
* @inheritdoc
128+
*/
129+
public $labelOptions = [];
130+
126131
/**
127132
* @var integer the hint display type. If set to `self::HINT_DEFAULT`, the hint will be displayed as a text block below
128133
* each input. If set to `self::HINT_SPECIAL`, then the `hintSettings` will be applied to display the field
@@ -243,31 +248,33 @@ class ActiveField extends YiiActiveField
243248
public $contentAfterHint = '';
244249

245250
/**
246-
* @var string the template for checkboxes and radios in default layout (applicable for BS4 only)
251+
* @var string the template for rendering checkboxes and radios for a default Bootstrap markup without an enclosed
252+
* label
247253
*/
248254
public $checkTemplate = "{input}\n{label}\n{error}\n{hint}";
249255

250256
/**
251-
* @var string the `enclosed by label` template for checkboxes and radios in default layout (applicable for BS4 only)
257+
* @var string the template for rendering checkboxes and radios for a default Bootstrap markup with an enclosed
258+
* label
252259
*/
253260
public $checkEnclosedTemplate = "{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}";
254261

255262
/**
256263
* @var array the HTML attributes for the container wrapping BS4 checkbox or radio controls within which the content
257-
* will be rendered via the [[checkTemplate]] or [[checkEnclosedTemplate]] (applicable for BS4 only)
264+
* will be rendered via the [[checkTemplate]] or [[checkEnclosedTemplate]]
258265
*/
259266
public $checkWrapperOptions = [];
260267

261268
/**
262269
* @var array addon options for text and password inputs. The following settings can be configured:
263270
* - `prepend`: _array_, the prepend addon configuration
264-
* - `content`: _string_, the prepend addon content
265-
* - `asButton`: _boolean_, whether the addon is a button or button group. Defaults to false.
266-
* - `options`: _array_, the HTML attributes to be added to the container.
271+
* - `content`: _string_, the prepend addon content
272+
* - `asButton`: _boolean_, whether the addon is a button or button group. Defaults to false.
273+
* - `options`: _array_, the HTML attributes to be added to the container.
267274
* - `append`: _array_, the append addon configuration
268-
* - `content`: _string_|_array_, the append addon content
269-
* - `asButton`: _boolean_, whether the addon is a button or button group. Defaults to false.
270-
* - `options`: _array_, the HTML attributes to be added to the container.
275+
* - `content`: _string_|_array_, the append addon content
276+
* - `asButton`: _boolean_, whether the addon is a button or button group. Defaults to false.
277+
* - `options`: _array_, the HTML attributes to be added to the container.
271278
* - `groupOptions`: _array_, HTML options for the input group
272279
* - `contentBefore`: _string_, content placed before addon
273280
* - `contentAfter`: _string_, content placed after addon
@@ -314,7 +321,7 @@ class ActiveField extends YiiActiveField
314321
public $autoPlaceholder;
315322

316323
/**
317-
* @var array options for the wrapper tag, used in the `{beginWrapper}` placeholder
324+
* @var array options for the wrapper tag, used in the `{beginWrapper}` token within [[template]].
318325
*/
319326
public $wrapperOptions = [];
320327

@@ -573,7 +580,6 @@ public function fileInput($options = [])
573580
return parent::fileInput($options);
574581
}
575582
Html::removeCssClass($options, 'form-control');
576-
Html::removeCssClass($this->labelOptions, 'control-label');
577583
Html::addCssClass($options, 'custom-file-input');
578584
Html::addCssClass($this->labelOptions, 'custom-file-label');
579585
$this->template = "{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}";
@@ -805,8 +811,7 @@ public function staticInput($options = [])
805811
{
806812
$content = isset($this->staticValue) ? $this->staticValue :
807813
Html::getAttributeValue($this->model, $this->attribute);
808-
$css = $this->form->isBs4() ? 'form-control-plaintext' : 'form-control-static';
809-
Html::addCssClass($options, $css);
814+
$this->form->addCssClass($options, ActiveForm::BS_FORM_CONTROL_STATIC);
810815
$this->parts['{input}'] = Html::tag('div', $content, $options);
811816
$this->_isStatic = true;
812817
return $this;
@@ -971,30 +976,29 @@ protected function getToggleField($type = self::TYPE_CHECKBOX, $options = [], $e
971976
unset($options['template']);
972977
}
973978
$prefix = $isBs4 ? ($custom ? 'custom-control' : 'form-check') : $type;
979+
Html::removeCssClass($options, 'form-control');
980+
$this->form->removeCssClass($this->labelOptions, ActiveForm::BS_CONTROL_LABEL);
974981
Html::addCssClass($this->checkWrapperOptions, $prefix);
975-
Html::removeCssClass($this->labelOptions, 'control-label');
976982
if ($isBs4) {
977983
Html::addCssClass($this->labelOptions, "{$prefix}-label");
978984
Html::addCssClass($options, "{$prefix}-input");
979985
if ($custom) {
980986
Html::addCssClass($this->checkWrapperOptions, "custom-{$type}");
981987
}
982-
Html::removeCssClass($options, 'form-control');
983988
} elseif (!$enclosedByLabel) {
984989
Html::addCssClass($this->checkWrapperOptions, "not-enclosed");
985990
}
986991
$this->template = Html::tag('div', $this->template, $this->checkWrapperOptions);
987-
if ($this->form->type === ActiveForm::TYPE_HORIZONTAL) {
988-
$css = $this->getColCss($this->deviceSize) . $this->labelSpan;
989-
Html::removeCssClass($this->labelOptions, ['control-label', 'col-form-label', $css]);
992+
if ($this->form->isHorizontal()) {
993+
Html::removeCssClass($this->labelOptions, $this->getColCss($this->deviceSize) . $this->labelSpan);
990994
if ($this->autoOffset) {
991995
$this->template = Html::tag('div', '', ['class' => $this->_labelCss]) .
992996
Html::tag('div', $this->template, ['class' => $this->_inputCss]);
993997
} else {
994998
Html::removeCssClass($this->options, 'row');
995999
}
9961000
}
997-
if ($this->form->type === ActiveForm::TYPE_INLINE) {
1001+
if ($this->form->isInline()) {
9981002
Html::removeCssClass($this->labelOptions, ActiveForm::SCREEN_READER);
9991003
}
10001004
if ($enclosedByLabel) {
@@ -1063,27 +1067,29 @@ protected function initActiveField()
10631067
$this->showLabels = $this->enableLabel;
10641068
}
10651069
$isBs4 = $this->form->isBs4();
1070+
$isInline = $this->form->isInline();
1071+
$isHorizontal = $this->form->isHorizontal();
10661072
if ($isBs4) {
10671073
$errCss = $this->form->tooltipStyleFeedback ? 'invalid-tooltip' : 'invalid-feedback';
10681074
Html::addCssClass($this->errorOptions, $errCss);
10691075
}
10701076
$showLabels = $this->getConfigParam('showLabels');
10711077
$this->_isHintSpecial = $this->hintType === self::HINT_SPECIAL;
1072-
if ($this->form->type === ActiveForm::TYPE_INLINE && !isset($this->autoPlaceholder) && $showLabels !== true) {
1078+
if ($isInline && !isset($this->autoPlaceholder) && $showLabels !== true) {
10731079
$this->autoPlaceholder = true;
10741080
} elseif (!isset($this->autoPlaceholder)) {
10751081
$this->autoPlaceholder = false;
10761082
}
1077-
if ($this->form->type === ActiveForm::TYPE_VERTICAL && !$isBs4) {
1078-
Html::addCssClass($this->labelOptions, 'control-label');
1083+
if (!isset($this->labelOptions['class']) && ($isHorizontal || !$isBs4 && !$isInline)) {
1084+
$this->labelOptions['class'] = $this->form->getCssClass(ActiveForm::BS_CONTROL_LABEL);
10791085
}
10801086
if ($showLabels === ActiveForm::SCREEN_READER) {
10811087
Html::addCssClass($this->labelOptions, ActiveForm::SCREEN_READER);
10821088
}
10831089
if ($this->highlightAddon) {
10841090
Html::addCssClass($this->options, 'highlight-addon');
10851091
}
1086-
if ($this->form->type === ActiveForm::TYPE_HORIZONTAL) {
1092+
if ($isHorizontal) {
10871093
$this->initHorizontal();
10881094
}
10891095
$this->initLabels();
@@ -1145,9 +1151,6 @@ protected function initHorizontal()
11451151
$size = $this->getConfigParam('deviceSize', '');
11461152
if ($this->form->isBs4()) {
11471153
Html::addCssClass($this->options, 'row');
1148-
Html::addCssClass($this->labelOptions, 'col-form-label');
1149-
} else {
1150-
Html::addCssClass($this->labelOptions, 'control-label');
11511154
}
11521155
// check horizontalCssClasses['wrapper'] if there is a col- class
11531156
if (isset($hor['wrapper']) && strpos($hor['wrapper'], 'col-') !== false) {
@@ -1540,11 +1543,10 @@ protected function getFeedbackIcon($config, $cat, $type, $prefix, $id)
15401543
$key = $id . '-' . $cat;
15411544
$this->inputOptions['aria-describedby'] = empty($this->inputOptions['aria-describedby']) ? $key :
15421545
$this->inputOptions['aria-describedby'] . ' ' . $key;
1543-
Html::addCssClass($options, 'form-control-feedback');
1544-
Html::addCssClass($options, 'kv-feedback-' . $cat);
1545-
1546+
Html::addCssClass($options, ['form-control-feedback', "kv-feedback-{$cat}"]);
15461547
$icon = $type === 'raw' ? $markup : Html::tag('i', '', ['class' => $prefix . $markup]);
1547-
return Html::tag('span', $icon, $options) . Html::tag('span', $desc, ['id' => $key, 'class' => 'sr-only']);
1548+
return Html::tag('span', $icon, $options) .
1549+
Html::tag('span', $desc, ['id' => $key, 'class' => ActiveForm::SCREEN_READER]);
15481550
}
15491551

15501552
/**

src/ActiveForm.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.5.4
7+
* @version 1.5.5
88
*/
99

1010
namespace kartik\form;
@@ -226,6 +226,33 @@ public function registerAssets()
226226
$view->registerJs($js);
227227
}
228228

229+
/**
230+
* Whether an inline layout form
231+
* @return bool
232+
*/
233+
public function isInline()
234+
{
235+
return $this->type === self::TYPE_INLINE;
236+
}
237+
238+
/**
239+
* Whether a horizontal layout form
240+
* @return bool
241+
*/
242+
public function isHorizontal()
243+
{
244+
return $this->type === self::TYPE_HORIZONTAL;
245+
}
246+
247+
/**
248+
* Whether a vertical layout form
249+
* @return bool
250+
*/
251+
public function isVertical()
252+
{
253+
return !$this->isHorizontal() && !$this->isInline();
254+
}
255+
229256
/**
230257
* Initializes the form configuration array and parameters for the form.
231258
*
@@ -241,7 +268,7 @@ protected function initForm()
241268
}
242269
$this->formConfig = array_replace_recursive($this->_config[$this->type], $this->formConfig);
243270
$css = ["form-{$this->type}"];
244-
if ($this->type === self::TYPE_HORIZONTAL) {
271+
if ($this->isHorizontal()) {
245272
$css[] = 'kv-form-horizontal';
246273
}
247274
if ($this->isBs4()) {

src/ActiveFormAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.5.4
7+
* @version 1.5.5
88
*/
99

1010
namespace kartik\form;

src/assets/css/activeform.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
33
* @package yii2-widgets
44
* @subpackage yii2-widget-activeform
5-
* @version 1.5.4
5+
* @version 1.5.5
66
*
77
* Active Form Styling for Bootstrap 3.x & Bootstrap 4.x
88
* Built for Yii Framework 2.0

src/assets/css/activeform.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/js/activeform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @package yii2-widget-activeform
33
* @author Kartik Visweswaran <[email protected]>
44
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
5-
* @version 1.5.4
5+
* @version 1.5.5
66
*
77
* Active Field Hints Display Module
88
*

src/assets/js/activeform.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)