diff --git a/extension.meta.xml b/extension.meta.xml index db909f1..6141e35 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -3,17 +3,22 @@ Number Field Dedicated number storage https://github.com/symphonycms/numberfield - http://getsymphony.com/discuss/thread/144/ + https://www.getsymphony.com/discuss/thread/144/ + https://github.com/symphonycms/numberfield/issues Field Types Symphony Team - http://getsymphony.com + https://www.getsymphony.com + + - Accept comma-notation in decimal input values ([#19](https://github.com/symphonycms/numberfield/issues/19)) + - Added missing issues-url to extension.meta.xml + - PHP7 Compatibility for Symphony 2.x.x diff --git a/fields/field.number.php b/fields/field.number.php index 4c4dab4..a831e60 100755 --- a/fields/field.number.php +++ b/fields/field.number.php @@ -100,12 +100,17 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWit public function checkPostFieldData($data, &$message, $entry_id = null) { $message = NULL; - if($this->get('required') == 'yes' && strlen($data) == 0){ + // transform comma-based notation into dot-based notation so it + // doesn't throw an error (as the comma will be replaced before + // saving the value in the database) + $value = str_replace(',', '.', $data); + + if($this->get('required') == 'yes' && strlen($value) == 0){ $message = __('ā€˜%sā€™ is a required field.', array($this->get('label'))); return self::__MISSING_FIELDS__; } - if(strlen($data) > 0 && !is_numeric($data)) { + if(strlen($value) > 0 && !is_numeric($value)) { $message = __('Must be a number.'); return self::__INVALID_FIELDS__; } @@ -116,10 +121,13 @@ public function checkPostFieldData($data, &$message, $entry_id = null) { public function processRawFieldData($data, &$status, &$message=null, $simulate = false, $entry_id = null) { $status = self::__OK__; - if (strlen(trim($data)) == 0) return array(); + // transform comma-based notation into dot-based notation + $value = str_replace(',', '.', $data); + + if (strlen(trim($value)) == 0) return array(); $result = array( - 'value' => $data + 'value' => $value ); return $result;