|
4 | 4 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 - 2018 |
5 | 5 | * @package yii2-widgets |
6 | 6 | * @subpackage yii2-widget-activeform |
7 | | - * @version 1.5.4 |
| 7 | + * @version 1.5.5 |
8 | 8 | */ |
9 | 9 |
|
10 | 10 | namespace kartik\form; |
@@ -123,6 +123,11 @@ class ActiveField extends YiiActiveField |
123 | 123 | */ |
124 | 124 | public $renderEmptyWrapper = false; |
125 | 125 |
|
| 126 | + /** |
| 127 | + * @inheritdoc |
| 128 | + */ |
| 129 | + public $labelOptions = []; |
| 130 | + |
126 | 131 | /** |
127 | 132 | * @var integer the hint display type. If set to `self::HINT_DEFAULT`, the hint will be displayed as a text block below |
128 | 133 | * 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 |
243 | 248 | public $contentAfterHint = ''; |
244 | 249 |
|
245 | 250 | /** |
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 |
247 | 253 | */ |
248 | 254 | public $checkTemplate = "{input}\n{label}\n{error}\n{hint}"; |
249 | 255 |
|
250 | 256 | /** |
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 |
252 | 259 | */ |
253 | 260 | public $checkEnclosedTemplate = "{beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint}"; |
254 | 261 |
|
255 | 262 | /** |
256 | 263 | * @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]] |
258 | 265 | */ |
259 | 266 | public $checkWrapperOptions = []; |
260 | 267 |
|
261 | 268 | /** |
262 | 269 | * @var array addon options for text and password inputs. The following settings can be configured: |
263 | 270 | * - `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. |
267 | 274 | * - `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. |
271 | 278 | * - `groupOptions`: _array_, HTML options for the input group |
272 | 279 | * - `contentBefore`: _string_, content placed before addon |
273 | 280 | * - `contentAfter`: _string_, content placed after addon |
@@ -314,7 +321,7 @@ class ActiveField extends YiiActiveField |
314 | 321 | public $autoPlaceholder; |
315 | 322 |
|
316 | 323 | /** |
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]]. |
318 | 325 | */ |
319 | 326 | public $wrapperOptions = []; |
320 | 327 |
|
@@ -573,7 +580,6 @@ public function fileInput($options = []) |
573 | 580 | return parent::fileInput($options); |
574 | 581 | } |
575 | 582 | Html::removeCssClass($options, 'form-control'); |
576 | | - Html::removeCssClass($this->labelOptions, 'control-label'); |
577 | 583 | Html::addCssClass($options, 'custom-file-input'); |
578 | 584 | Html::addCssClass($this->labelOptions, 'custom-file-label'); |
579 | 585 | $this->template = "{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}"; |
@@ -805,8 +811,7 @@ public function staticInput($options = []) |
805 | 811 | { |
806 | 812 | $content = isset($this->staticValue) ? $this->staticValue : |
807 | 813 | 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); |
810 | 815 | $this->parts['{input}'] = Html::tag('div', $content, $options); |
811 | 816 | $this->_isStatic = true; |
812 | 817 | return $this; |
@@ -971,30 +976,29 @@ protected function getToggleField($type = self::TYPE_CHECKBOX, $options = [], $e |
971 | 976 | unset($options['template']); |
972 | 977 | } |
973 | 978 | $prefix = $isBs4 ? ($custom ? 'custom-control' : 'form-check') : $type; |
| 979 | + Html::removeCssClass($options, 'form-control'); |
| 980 | + $this->form->removeCssClass($this->labelOptions, ActiveForm::BS_CONTROL_LABEL); |
974 | 981 | Html::addCssClass($this->checkWrapperOptions, $prefix); |
975 | | - Html::removeCssClass($this->labelOptions, 'control-label'); |
976 | 982 | if ($isBs4) { |
977 | 983 | Html::addCssClass($this->labelOptions, "{$prefix}-label"); |
978 | 984 | Html::addCssClass($options, "{$prefix}-input"); |
979 | 985 | if ($custom) { |
980 | 986 | Html::addCssClass($this->checkWrapperOptions, "custom-{$type}"); |
981 | 987 | } |
982 | | - Html::removeCssClass($options, 'form-control'); |
983 | 988 | } elseif (!$enclosedByLabel) { |
984 | 989 | Html::addCssClass($this->checkWrapperOptions, "not-enclosed"); |
985 | 990 | } |
986 | 991 | $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); |
990 | 994 | if ($this->autoOffset) { |
991 | 995 | $this->template = Html::tag('div', '', ['class' => $this->_labelCss]) . |
992 | 996 | Html::tag('div', $this->template, ['class' => $this->_inputCss]); |
993 | 997 | } else { |
994 | 998 | Html::removeCssClass($this->options, 'row'); |
995 | 999 | } |
996 | 1000 | } |
997 | | - if ($this->form->type === ActiveForm::TYPE_INLINE) { |
| 1001 | + if ($this->form->isInline()) { |
998 | 1002 | Html::removeCssClass($this->labelOptions, ActiveForm::SCREEN_READER); |
999 | 1003 | } |
1000 | 1004 | if ($enclosedByLabel) { |
@@ -1063,27 +1067,29 @@ protected function initActiveField() |
1063 | 1067 | $this->showLabels = $this->enableLabel; |
1064 | 1068 | } |
1065 | 1069 | $isBs4 = $this->form->isBs4(); |
| 1070 | + $isInline = $this->form->isInline(); |
| 1071 | + $isHorizontal = $this->form->isHorizontal(); |
1066 | 1072 | if ($isBs4) { |
1067 | 1073 | $errCss = $this->form->tooltipStyleFeedback ? 'invalid-tooltip' : 'invalid-feedback'; |
1068 | 1074 | Html::addCssClass($this->errorOptions, $errCss); |
1069 | 1075 | } |
1070 | 1076 | $showLabels = $this->getConfigParam('showLabels'); |
1071 | 1077 | $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) { |
1073 | 1079 | $this->autoPlaceholder = true; |
1074 | 1080 | } elseif (!isset($this->autoPlaceholder)) { |
1075 | 1081 | $this->autoPlaceholder = false; |
1076 | 1082 | } |
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); |
1079 | 1085 | } |
1080 | 1086 | if ($showLabels === ActiveForm::SCREEN_READER) { |
1081 | 1087 | Html::addCssClass($this->labelOptions, ActiveForm::SCREEN_READER); |
1082 | 1088 | } |
1083 | 1089 | if ($this->highlightAddon) { |
1084 | 1090 | Html::addCssClass($this->options, 'highlight-addon'); |
1085 | 1091 | } |
1086 | | - if ($this->form->type === ActiveForm::TYPE_HORIZONTAL) { |
| 1092 | + if ($isHorizontal) { |
1087 | 1093 | $this->initHorizontal(); |
1088 | 1094 | } |
1089 | 1095 | $this->initLabels(); |
@@ -1145,9 +1151,6 @@ protected function initHorizontal() |
1145 | 1151 | $size = $this->getConfigParam('deviceSize', ''); |
1146 | 1152 | if ($this->form->isBs4()) { |
1147 | 1153 | Html::addCssClass($this->options, 'row'); |
1148 | | - Html::addCssClass($this->labelOptions, 'col-form-label'); |
1149 | | - } else { |
1150 | | - Html::addCssClass($this->labelOptions, 'control-label'); |
1151 | 1154 | } |
1152 | 1155 | // check horizontalCssClasses['wrapper'] if there is a col- class |
1153 | 1156 | if (isset($hor['wrapper']) && strpos($hor['wrapper'], 'col-') !== false) { |
@@ -1540,11 +1543,10 @@ protected function getFeedbackIcon($config, $cat, $type, $prefix, $id) |
1540 | 1543 | $key = $id . '-' . $cat; |
1541 | 1544 | $this->inputOptions['aria-describedby'] = empty($this->inputOptions['aria-describedby']) ? $key : |
1542 | 1545 | $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}"]); |
1546 | 1547 | $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]); |
1548 | 1550 | } |
1549 | 1551 |
|
1550 | 1552 | /** |
|
0 commit comments