Skip to content

Commit 5f5ef64

Browse files
authored
Merge pull request #20212 from alxlnk/master
Add regex property to one of required option to MaskedInput inititialization
2 parents 97466bd + 32688de commit 5f5ef64

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Yii Framework 2 Change Log
88
- Bug #16116: Codeception: oci does not support enabling/disabling integrity check (@terabytesoftw)
99
- Bug #20191: Fix `ActiveRecord::getDirtyAttributes()` for JSON columns with multi-dimensional array values (brandonkelly)
1010
- Bug #20175: Fix bad result for pagination when used with GridView (@lav45)
11+
- Bug #20211: Add acceptable parameters to `MaskedInput::init()` method (alxlnk)
1112

1213

1314
2.0.50 May 30, 2024

framework/widgets/MaskedInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class MaskedInput extends InputWidget
132132
public function init()
133133
{
134134
parent::init();
135-
if (empty($this->mask) && empty($this->clientOptions['alias'])) {
136-
throw new InvalidConfigException("Either the 'mask' property or the 'clientOptions[\"alias\"]' property must be set.");
135+
if (empty($this->mask) && empty($this->clientOptions['regex']) && empty($this->clientOptions['alias'])) {
136+
throw new InvalidConfigException("Either the 'mask' property, 'clientOptions[\"regex\"]' or the 'clientOptions[\"alias\"]' property must be set.");
137137
}
138138
}
139139

tests/framework/widgets/ActiveFieldTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ public function testInputOptionsTransferToWidget()
677677
]);
678678
$this->assertStringContainsString('placeholder="pholder_direct"', (string) $widget);
679679

680+
// use regex clientOptions instead mask
681+
$widget = $this->activeField->widget(TestMaskedInput::className(), [
682+
'options' => ['placeholder' => 'pholder_direct'],
683+
'clientOptions' => ['regex' => '^.*$'],
684+
]);
685+
$this->assertStringContainsString('placeholder="pholder_direct"', (string) $widget);
686+
680687
// transfer options from ActiveField to widget
681688
$this->activeField->inputOptions = ['placeholder' => 'pholder_input'];
682689
$widget = $this->activeField->widget(TestMaskedInput::className(), [

0 commit comments

Comments
 (0)