From 9ebb903a2e8de91474862417986b4a07e8100fb3 Mon Sep 17 00:00:00 2001 From: Oleksandr Lynnyk Date: Mon, 24 Jun 2024 17:40:29 +0300 Subject: [PATCH 1/4] Add regex property to one of required option. --- framework/widgets/MaskedInput.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/widgets/MaskedInput.php b/framework/widgets/MaskedInput.php index 7513169e9b0..f7307986c0e 100644 --- a/framework/widgets/MaskedInput.php +++ b/framework/widgets/MaskedInput.php @@ -132,8 +132,8 @@ class MaskedInput extends InputWidget public function init() { parent::init(); - if (empty($this->mask) && empty($this->clientOptions['alias'])) { - throw new InvalidConfigException("Either the 'mask' property or the 'clientOptions[\"alias\"]' property must be set."); + if (empty($this->mask) && empty($this->clientOptions['regex']) && empty($this->clientOptions['alias'])) { + throw new InvalidConfigException("Either the 'mask' property, 'clientOptions[\"regex\"]' or the 'clientOptions[\"alias\"]' property must be set."); } } From 0a5b71f4d1ba3bf82ca57f9d2a5b455180d49dc0 Mon Sep 17 00:00:00 2001 From: Oleksandr Lynnyk Date: Wed, 3 Jul 2024 12:11:29 +0300 Subject: [PATCH 2/4] Add test. --- tests/framework/widgets/ActiveFieldTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/framework/widgets/ActiveFieldTest.php b/tests/framework/widgets/ActiveFieldTest.php index 25f77b73bfa..782358a72ec 100644 --- a/tests/framework/widgets/ActiveFieldTest.php +++ b/tests/framework/widgets/ActiveFieldTest.php @@ -10,6 +10,7 @@ use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; use Yii; use yii\base\DynamicModel; +use yii\base\InvalidConfigException; use yii\web\AssetManager; use yii\web\View; use yii\widgets\ActiveField; @@ -691,6 +692,16 @@ public function testInputOptionsTransferToWidget() 'options' => ['placeholder' => 'pholder_both_direct'] ]); $this->assertStringContainsString('placeholder="pholder_both_direct"', (string) $widget); + + try { + $widget = $this->activeField->widget(TestMaskedInput::className(), [ + 'clientOptions' => [ + 'regex' => '^.*$', + ], + ]); + } catch (InvalidConfigException $exception) { + $this->fail($exception->getMessage()); + } } /** From c9b425e8c8dcc572030ef9ed6abe7253eea65e8b Mon Sep 17 00:00:00 2001 From: Oleksandr Lynnyk Date: Wed, 3 Jul 2024 12:13:46 +0300 Subject: [PATCH 3/4] Update CHANGELOG.md --- framework/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6d6fa2e2e03..b36e8b1131c 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -8,6 +8,7 @@ Yii Framework 2 Change Log - Bug #16116: Codeception: oci does not support enabling/disabling integrity check (@terabytesoftw) - Bug #20191: Fix `ActiveRecord::getDirtyAttributes()` for JSON columns with multi-dimensional array values (brandonkelly) - Bug #20175: Fix bad result for pagination when used with GridView (@lav45) +- Bug #20211: Add acceptable parameters to `MaskedInput::init()` method (alxlnk) 2.0.50 May 30, 2024 From 32688de621cddaccc342f8fedf2405362c255431 Mon Sep 17 00:00:00 2001 From: Oleksandr Lynnyk Date: Thu, 4 Jul 2024 13:19:56 +0300 Subject: [PATCH 4/4] Update active field options test. --- tests/framework/widgets/ActiveFieldTest.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/framework/widgets/ActiveFieldTest.php b/tests/framework/widgets/ActiveFieldTest.php index 782358a72ec..b38cfa29c8d 100644 --- a/tests/framework/widgets/ActiveFieldTest.php +++ b/tests/framework/widgets/ActiveFieldTest.php @@ -10,7 +10,6 @@ use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; use Yii; use yii\base\DynamicModel; -use yii\base\InvalidConfigException; use yii\web\AssetManager; use yii\web\View; use yii\widgets\ActiveField; @@ -678,6 +677,13 @@ public function testInputOptionsTransferToWidget() ]); $this->assertStringContainsString('placeholder="pholder_direct"', (string) $widget); + // use regex clientOptions instead mask + $widget = $this->activeField->widget(TestMaskedInput::className(), [ + 'options' => ['placeholder' => 'pholder_direct'], + 'clientOptions' => ['regex' => '^.*$'], + ]); + $this->assertStringContainsString('placeholder="pholder_direct"', (string) $widget); + // transfer options from ActiveField to widget $this->activeField->inputOptions = ['placeholder' => 'pholder_input']; $widget = $this->activeField->widget(TestMaskedInput::className(), [ @@ -692,16 +698,6 @@ public function testInputOptionsTransferToWidget() 'options' => ['placeholder' => 'pholder_both_direct'] ]); $this->assertStringContainsString('placeholder="pholder_both_direct"', (string) $widget); - - try { - $widget = $this->activeField->widget(TestMaskedInput::className(), [ - 'clientOptions' => [ - 'regex' => '^.*$', - ], - ]); - } catch (InvalidConfigException $exception) { - $this->fail($exception->getMessage()); - } } /**