Skip to content

Commit e983a2b

Browse files
committed
Updates to release v1.6.3 fixes #136 fixes #137 fixes #138
1 parent 98dbf78 commit e983a2b

12 files changed

+163
-33
lines changed

CHANGE.md

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

4+
## Version 1.6.3
5+
6+
**Date**: 28-Jul-2023
7+
8+
- (enh #138): Enhance required star for bootstrap 5 floating labels.
9+
- (enh #137): Overflowing labels in CheckboxList don't break correctly with Bootstrap 4.
10+
- (enh #136): Enhance ActiveForm to dynamically configure `enabled`, `readonly` and `staticOnly` flags.
11+
412
## Version 1.6.2
513

614
**Date**: 27-Feb-2022

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 - 2022, Kartik Visweswaran
1+
Copyright (c) 2015 - 2023, Kartik Visweswaran
22
Krajee.com
33
All rights reserved.
44

src/ActiveField.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.6.2
7+
* @version 1.6.3
88
*/
99

1010
namespace kartik\form;
@@ -643,11 +643,13 @@ public function hint($content, $options = [])
643643
{
644644
if ($this->getConfigParam('showHints') === false) {
645645
$this->parts['{hint}'] = '';
646+
646647
return $this;
647648
}
648649
if ($this->_isHintSpecial) {
649650
Html::addCssClass($options, 'kv-hint-block');
650651
}
652+
651653
return parent::hint($this->generateHint($content), $options);
652654
}
653655

@@ -864,8 +866,11 @@ public function render($content = null)
864866
}
865867
$this->template = Lib::strtr($this->template, ['{hint}' => $this->_settings['hint']]);
866868
}
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) {
869874
$this->buildTemplate();
870875
$this->staticInput();
871876
} else {
@@ -925,7 +930,8 @@ public function widget($class, $config = [])
925930
*/
926931
public function staticInput($options = [])
927932
{
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);
929935
$this->form->addCssClass($options, ActiveForm::BS_FORM_CONTROL_STATIC);
930936
$this->parts['{input}'] = Html::tag('div', $content, $options);
931937
$this->_isStatic = true;
@@ -1141,19 +1147,35 @@ protected function getToggleField($type = self::TYPE_CHECKBOX, $options = [], $e
11411147
return parent::$type($options, false);
11421148
}
11431149

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+
11441170
/**
11451171
* Validates and sets disabled or readonly inputs
11461172
*
11471173
* @param array $options the HTML attributes for the input
11481174
*/
11491175
protected function initDisability(&$options)
11501176
{
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);
11571179
}
11581180

11591181
/**
@@ -1739,7 +1761,12 @@ protected function getToggleFieldList($type, $items, $options = [], $asBtnGrp =
17391761
$disabled = ArrayHelper::remove($options, 'disabledItems', []);
17401762
$readonly = ArrayHelper::remove($options, 'readonlyItems', []);
17411763
$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+
17431770
if ($asBtnGrp) {
17441771
$css = ['btn-group'];
17451772
if (!$isBs5) {

src/ActiveForm.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.6.2
7+
* @version 1.6.3
88
*/
99

1010
namespace kartik\form;
@@ -151,17 +151,42 @@ class ActiveForm extends YiiActiveForm implements BootstrapInterface
151151
public $inlineFormCssClass;
152152

153153
/**
154-
* @var boolean whether all data in form are to be static inputs
154+
* @var boolean|Closure whether all inputs in form are to be rendered as bootstrap 5 static text inputs. For
155+
* advanced configuration (e.g. dynamically setting different flags for different fields), this can be setup as a
156+
* Closure callback. When setup as a Closure callback, you can receive the model instance and the active field
157+
* object instance as parameters. For example:
158+
*
159+
* ```
160+
* 'staticOnly' => function ($model, $field) {
161+
* return in_array($field->attribute, $model->staticOnlyAttributes());
162+
* }
163+
* ```
155164
*/
156165
public $staticOnly = false;
157166

158167
/**
159-
* @var boolean whether all inputs in form are to be disabled
168+
* @var boolean|Closure whether all inputs in form are to be disabled. For advanced configuration (e.g. dynamically
169+
* setting different flags for different fields), this can be setup as a Closure callback. When setup as a Closure
170+
* callback, you can receive the model instance and the active field object instance as parameters. For example:
171+
*
172+
* ```
173+
* 'disabled' => function ($model, $field) {
174+
* return in_array($field->attribute, $model->disabledAttributes());
175+
* }
176+
* ```
160177
*/
161178
public $disabled = false;
162179

163180
/**
164-
* @var boolean whether all inputs in form are to be readonly.
181+
* @var boolean|Closure whether all inputs in form are to be readonly. For advanced configuration (e.g. dynamically
182+
* setting different flags for different fields), this can be setup as a Closure callback. When setup as a Closure
183+
* callback, you can receive the model instance and the active field object instance as parameters. For example:
184+
*
185+
* ```
186+
* 'readonly' => function ($model, $field) {
187+
* return in_array($field->attribute, $model->readonlyAttributes());
188+
* }
189+
* ```
165190
*/
166191
public $readonly = false;
167192

src/ActiveFormAsset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.6.2
7+
* @version 1.6.3
88
*/
99

1010
namespace kartik\form;

src/Bs4CustomFileInputAsset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

33
/**
4-
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
4+
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
55
* @package yii2-widgets
66
* @subpackage yii2-widget-activeform
7-
* @version 1.6.2
7+
* @version 1.6.3
88
*/
99

1010
namespace kartik\form;

0 commit comments

Comments
 (0)