_initDefaults(); $this->addValidator('Float', false, ['locale' => $this->getLocale()]); $class = (array) $this->getAttrib('class'); $class[] = 'autoNumeric'; $this->setAttrib('class', $class); } protected function _initDefaults() { $_locale = 'en_US'; $_precision = 2; $_group = ','; $_decimal = '.'; $_negative = true; if (null === $this->_locale) { if (Zend_Registry::isRegistered('Zend_Locale')) { $this->_locale = Zend_Registry::get('Zend_Locale'); } else { $this->_locale = $_locale; } } if (null === $this->_precision || null === $this->_group) { $_localeInfo = Zend_Locale_Data::getList($this->_locale, 'symbols'); if (null === $this->_group) { $this->_group = (empty($_localeInfo['group'])) ? $_group : $_localeInfo['group']; } if (null === $this->_decimal) { $this->_decimal = (empty($_localeInfo['decimal'])) ? $_decimal : $_localeInfo['decimal']; } } if (null === $this->_precision) { $this->_precision = $_precision; } if (null === $this->_negative) { $this->_negative = $_negative; } return $this; } protected function _filterValue(&$value, &$key) { parent::_filterValue($value, $key); if (!empty($value)) { $value = (string) $value; $value = str_replace($this->getGroup(), '', $value); $value = str_replace($this->getDecimal(), '.', $value); } } public function getValue() { $value = parent::getValue(); if ('' === $value) { $value = null; } return $value; } public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('Numeric') ->addDecorator('Errors') ->addDecorator('Description', ['tag' => 'p', 'class' => 'description']) ->addDecorator('HtmlTag', ['tag' => 'dd', 'id' => $this->getName() . '-element']) ->addDecorator('Label', ['tag' => 'dt']); } } public function getLocale() { return $this->_locale; } /** * Sets the locale * * @param string|Zend_Locale $locale * @return Qs_Form_Element_Numeric */ public function setLocale($locale = null) { $this->_locale = Zend_Locale::findLocale($locale); return $this; } public function getPrecision() { return $this->_precision; } /** * Set precision * @param int $precision * @return Qs_Form_Element_Numeric */ public function setPrecision($precision) { $this->_precision = (int) $precision; return $this; } /** * Set thousand separator * @param $separator * @return Qs_Form_Element_Numeric */ public function setGroup($separator) { $this->_group = (string) $separator; return $this; } public function getGroup() { return $this->_group; } /** * Set decimal separator * @param string $decimalPoint * @return Qs_Form_Element_Numeric */ public function setDecimal($decimalPoint) { $this->_decimal = (string) $decimalPoint; return $this; } public function getDecimal() { return $this->_decimal; } /** * Set flag allow or disallow negative values * @param bool $flag * @return Qs_Form_Element_Numeric */ public function setNegative($flag) { $this->_negative = (bool) $flag; return $this; } public function getNegative() { return $this->_negative; } }