/** * @inheritdoc */ public function init() { $this->alias = 'decimal'; parent::init(); if (is_null($this->thousandSeparator) || is_null($this->decimalSeparator)) { $formatter = Yii::$app->getFormatter(); if (preg_match('~^1(\\D*)000(\\D*)99$~', $formatter->asDecimal(1000.99), $match)) { if (is_null($this->thousandSeparator)) { $this->thousandSeparator = $match[1]; } if (is_null($this->decimalSeparator)) { $this->decimalSeparator = $match[2]; } } else { if (is_null($this->thousandSeparator)) { if (array_key_exists(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $formatter->numberFormatterSymbols)) { $this->thousandSeparator = $formatter->numberFormatterSymbols[NumberFormatter::GROUPING_SEPARATOR_SYMBOL]; } else { $this->thousandSeparator = $formatter->thousandSeparator; } } if (is_null($this->decimalSeparator)) { if (array_key_exists(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $formatter->numberFormatterSymbols)) { $this->decimalSeparator = $formatter->numberFormatterSymbols[NumberFormatter::DECIMAL_SEPARATOR_SYMBOL]; } else { $this->decimalSeparator = $formatter->decimalSeparator; } } } if (is_null($this->thousandSeparator) || is_null($this->decimalSeparator)) { if (extension_loaded('intl')) { $numberFormatter = new NumberFormatter($formatter->locale, NumberFormatter::DECIMAL); if (is_null($this->thousandSeparator)) { $this->thousandSeparator = $numberFormatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); } if (is_null($this->decimalSeparator)) { $this->decimalSeparator = $numberFormatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); } } else { if (is_null($this->thousandSeparator)) { $this->thousandSeparator = ','; } if (is_null($this->decimalSeparator)) { $this->decimalSeparator = '.'; } } } } if (!array_key_exists('onUnMask', $this->clientOptions)) { $this->clientOptions['onUnMask'] = new JsExpression('function (maskedValue, unmaskedValue, opts) { return maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), \'g\'), \'\').replace(Inputmask.escapeRegex(opts.radixPoint), \'.\'); }'); } $this->clientOptions = array_merge(['rightAlign' => $this->rightAlign, 'digitsOptional' => $this->digitsOptional], $this->clientOptions, ['allowPlus' => $this->allowPlus, 'allowMinus' => $this->allowMinus, 'integerDigits' => $this->integerDigits, 'groupSeparator' => $this->thousandSeparator, 'autoGroup' => (bool) strlen($this->thousandSeparator), 'radixPoint' => $this->decimalSeparator, 'digits' => $this->digits]); }
/** * @inheritdoc */ public function init() { $this->alias = 'integer'; parent::init(); if (is_null($this->thousandSeparator)) { $formatter = Yii::$app->getFormatter(); if (preg_match('~^1(\\D*)000$~', $formatter->asInteger(1000), $match)) { $this->thousandSeparator = $match[1]; } elseif (array_key_exists(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $formatter->numberFormatterSymbols)) { $this->thousandSeparator = $formatter->numberFormatterSymbols[NumberFormatter::GROUPING_SEPARATOR_SYMBOL]; } else { $this->thousandSeparator = $formatter->thousandSeparator; } if (is_null($this->thousandSeparator)) { if (extension_loaded('intl')) { $numberFormatter = new NumberFormatter($formatter->locale, NumberFormatter::DECIMAL); $this->thousandSeparator = $numberFormatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); } else { $this->thousandSeparator = ','; } } } $this->clientOptions = array_merge(['rightAlign' => $this->rightAlign], $this->clientOptions, ['allowPlus' => $this->allowPlus, 'allowMinus' => $this->allowMinus, 'integerDigits' => $this->integerDigits, 'groupSeparator' => $this->thousandSeparator, 'autoGroup' => (bool) strlen($this->thousandSeparator)]); }
/** * @inheritdoc */ public function run() { $this->clientOptions = array_merge(['digitsOptional' => $this->digitsOptional, 'rightAlign' => $this->rightAlign], $this->clientOptions, ['allowMinus' => $this->allowMinus, 'allowPlus' => $this->allowPlus, 'integerDigits' => $this->integerDigits, 'groupSeparator' => $this->thousandSeparator, 'autoGroup' => strlen($this->thousandSeparator) > 0, 'radixPoint' => $this->decimalSeparator, 'digits' => $this->digits]); return parent::run(); }