Skip to content

Commit

Permalink
Merge pull request #20212 from alxlnk/master
Browse files Browse the repository at this point in the history
Add regex property to one of required option to MaskedInput inititialization
  • Loading branch information
mtangoo authored Jul 4, 2024
2 parents 97466bd + 32688de commit 5f5ef64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions framework/widgets/MaskedInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/framework/widgets/ActiveFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,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(), [
Expand Down

0 comments on commit 5f5ef64

Please sign in to comment.