Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex property to one of required option. #20212

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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.");

Check warning on line 136 in framework/widgets/MaskedInput.php

View check run for this annotation

Codecov / codecov/patch

framework/widgets/MaskedInput.php#L136

Added line #L136 was not covered by tests
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/framework/widgets/ActiveFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(), [
alxlnk marked this conversation as resolved.
Show resolved Hide resolved
'clientOptions' => [
'regex' => '^.*$',
],
]);
} catch (InvalidConfigException $exception) {
$this->fail($exception->getMessage());
}
}

/**
Expand Down
Loading