|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 - 2022 |
| 4 | + * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 - 2023 |
5 | 5 | * @package yii2-widgets |
6 | 6 | * @subpackage yii2-widget-activeform |
7 | | - * @version 1.6.2 |
| 7 | + * @version 1.6.3 |
8 | 8 | */ |
9 | 9 |
|
10 | 10 | namespace kartik\form; |
@@ -643,11 +643,13 @@ public function hint($content, $options = []) |
643 | 643 | { |
644 | 644 | if ($this->getConfigParam('showHints') === false) { |
645 | 645 | $this->parts['{hint}'] = ''; |
| 646 | + |
646 | 647 | return $this; |
647 | 648 | } |
648 | 649 | if ($this->_isHintSpecial) { |
649 | 650 | Html::addCssClass($options, 'kv-hint-block'); |
650 | 651 | } |
| 652 | + |
651 | 653 | return parent::hint($this->generateHint($content), $options); |
652 | 654 | } |
653 | 655 |
|
@@ -864,8 +866,11 @@ public function render($content = null) |
864 | 866 | } |
865 | 867 | $this->template = Lib::strtr($this->template, ['{hint}' => $this->_settings['hint']]); |
866 | 868 | } |
867 | | - |
868 | | - if ($this->form->staticOnly === true) { |
| 869 | + $staticOnly = $this->form->staticOnly; |
| 870 | + if (is_callable($staticOnly)) { |
| 871 | + $staticOnly = call_user_func($staticOnly, [$this->model, $this]); |
| 872 | + } |
| 873 | + if ($staticOnly === true) { |
869 | 874 | $this->buildTemplate(); |
870 | 875 | $this->staticInput(); |
871 | 876 | } else { |
@@ -925,7 +930,8 @@ public function widget($class, $config = []) |
925 | 930 | */ |
926 | 931 | public function staticInput($options = []) |
927 | 932 | { |
928 | | - $content = isset($this->staticValue) ? $this->staticValue : Html::getAttributeValue($this->model, $this->attribute); |
| 933 | + $content = isset($this->staticValue) ? $this->staticValue : Html::getAttributeValue($this->model, |
| 934 | + $this->attribute); |
929 | 935 | $this->form->addCssClass($options, ActiveForm::BS_FORM_CONTROL_STATIC); |
930 | 936 | $this->parts['{input}'] = Html::tag('div', $content, $options); |
931 | 937 | $this->_isStatic = true; |
@@ -1141,19 +1147,35 @@ protected function getToggleField($type = self::TYPE_CHECKBOX, $options = [], $e |
1141 | 1147 | return parent::$type($options, false); |
1142 | 1148 | } |
1143 | 1149 |
|
| 1150 | + /** |
| 1151 | + * Parses the form flag (for disabled/readonly). |
| 1152 | + * |
| 1153 | + * @param string $flag |
| 1154 | + * @param array $options |
| 1155 | + * @return void |
| 1156 | + */ |
| 1157 | + protected function parseFormFlag($flag, &$options) |
| 1158 | + { |
| 1159 | + if (!property_exists($this->form, $flag)) { |
| 1160 | + return; |
| 1161 | + } |
| 1162 | + $action = $this->form->$flag; |
| 1163 | + if ($action && is_callable($action)) { |
| 1164 | + $options[$flag] = call_user_func_array($action, [$this->model, $this]); |
| 1165 | + } else { |
| 1166 | + $options[$flag] = $action; |
| 1167 | + } |
| 1168 | + } |
| 1169 | + |
1144 | 1170 | /** |
1145 | 1171 | * Validates and sets disabled or readonly inputs |
1146 | 1172 | * |
1147 | 1173 | * @param array $options the HTML attributes for the input |
1148 | 1174 | */ |
1149 | 1175 | protected function initDisability(&$options) |
1150 | 1176 | { |
1151 | | - if ($this->form->disabled && !isset($options['disabled'])) { |
1152 | | - $options['disabled'] = true; |
1153 | | - } |
1154 | | - if ($this->form->readonly && !isset($options['readonly'])) { |
1155 | | - $options['readonly'] = true; |
1156 | | - } |
| 1177 | + $this->parseFormFlag('disabled', $options); |
| 1178 | + $this->parseFormFlag('readonly', $options); |
1157 | 1179 | } |
1158 | 1180 |
|
1159 | 1181 | /** |
@@ -1739,7 +1761,12 @@ protected function getToggleFieldList($type, $items, $options = [], $asBtnGrp = |
1739 | 1761 | $disabled = ArrayHelper::remove($options, 'disabledItems', []); |
1740 | 1762 | $readonly = ArrayHelper::remove($options, 'readonlyItems', []); |
1741 | 1763 | $cust = $this->isCustomControl($options); |
1742 | | - $pre = $cust ? ($isBs5 ? 'form-check' : 'custom-control') : ($notBs3 ? "me-1 mr-1 bs-{$type}" : ''); |
| 1764 | + if ($isBs5) { |
| 1765 | + $pre = ($cust ? '' : ' bs5-form-check ').'form-check'; |
| 1766 | + } else { |
| 1767 | + $pre = $cust ? 'custom-control' : 'form-check'; |
| 1768 | + } |
| 1769 | + |
1743 | 1770 | if ($asBtnGrp) { |
1744 | 1771 | $css = ['btn-group']; |
1745 | 1772 | if (!$isBs5) { |
|
0 commit comments