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

Update list of JS callbacks in MaskedInput #19420

Merged
merged 3 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -31,6 +31,7 @@ Yii Framework 2 Change Log
- Bug #19402: Add shutdown event and fix working directory in `yii\base\ErrorHandler` (WinterSilence)
- Enh #19416: Update and improve configurations for `yii\console\controllers\MessageController` (WinterSilence)
- Bug #19403: Fix types in `yii\web\SessionIterator` (WinterSilence)
- Enh #19420: Update list of JS callbacks in `yii\widgets\MaskedInput` (WinterSilence)


2.0.45 February 11, 2022
Expand Down
33 changes: 25 additions & 8 deletions framework/widgets/MaskedInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,26 @@ class MaskedInput extends InputWidget
* @var string the hashed variable to store the pluginOptions
*/
protected $_hashVar;

/**
* @var string[] the inputmask properties can be contained callbacks
*/
protected $_jsCallbacks = [
'oncomplete',
'onincomplete',
'oncleared',
'onKeyDown',
'onBeforeMask',
'onBeforePaste',
'onBeforeWrite',
'onUnMask',
'onKeyValidation',
'isComplete',
// @deprecated removed in 5.0:
'preValidation',
'postValidation',
// @deprecated removed in 4.0:
'canClearPosition'
];

/**
* Initializes the widget.
Expand Down Expand Up @@ -154,11 +173,9 @@ protected function initClientOptions()
$options = $this->clientOptions;
foreach ($options as $key => $value) {
if (
!$value instanceof JsExpression
&& in_array($key, [
'oncomplete', 'onincomplete', 'oncleared', 'onKeyUp', 'onKeyDown', 'onBeforeMask',
'onBeforePaste', 'onUnMask', 'isComplete', 'determineActiveMasksetIndex',
], true)
!empty($value)
&& !$value instanceof JsExpression
&& in_array($key, $this->_jsCallbacks, true)
) {
$options[$key] = new JsExpression($value);
}
Expand All @@ -178,10 +195,10 @@ public function registerClientScript()
$this->clientOptions['mask'] = $this->mask;
}
$this->hashPluginOptions($view);
if (is_array($this->definitions) && !empty($this->definitions)) {
if (!empty($this->definitions) && is_array($this->definitions)) {
$js .= ucfirst(self::PLUGIN_NAME) . '.extendDefinitions(' . Json::htmlEncode($this->definitions) . ');';
}
if (is_array($this->aliases) && !empty($this->aliases)) {
if (!empty($this->aliases) && is_array($this->aliases)) {
$js .= ucfirst(self::PLUGIN_NAME) . '.extendAliases(' . Json::htmlEncode($this->aliases) . ');';
}
$id = $this->options['id'];
Expand Down