/** * @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 = 'decimal'; $formatter = Yii::$app->getFormatter(); if (is_null($this->thousandSeparator) || is_null($this->decimalSeparator)) { 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)) { $this->thousandSeparator = $formatter->thousandSeparator; } if (is_null($this->decimalSeparator)) { $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 = '.'; } } } } parent::init(); }
/** * @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 init() { $this->alias = 'currency'; $formatter = Yii::$app->getFormatter(); if (is_null($this->currency)) { $this->currency = $formatter->currencyCode; } if (is_null($this->prefix) || is_null($this->suffix)) { if ($this->currency !== false && preg_match('~^(\\D*)1\\D*000\\D*99(\\D*)$~', $formatter->asCurrency(1000.99, $this->currency), $match)) { if (is_null($this->prefix)) { $this->prefix = $match[1]; } if (is_null($this->suffix)) { $this->suffix = $match[2]; } } else { if (is_null($this->prefix)) { $this->prefix = ''; } if (is_null($this->suffix)) { $this->suffix = ''; } } } if (is_null($this->thousandSeparator) || is_null($this->decimalSeparator)) { 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)) { $this->thousandSeparator = $formatter->thousandSeparator; } if (is_null($this->decimalSeparator)) { $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::MONETARY_GROUPING_SEPARATOR_SYMBOL); } if (is_null($this->decimalSeparator)) { $this->decimalSeparator = $numberFormatter->getSymbol(NumberFormatter::MONETARY_SEPARATOR_SYMBOL); } } else { if (is_null($this->thousandSeparator)) { $this->thousandSeparator = ','; } if (is_null($this->decimalSeparator)) { $this->decimalSeparator = '.'; } } } } parent::init(); }