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

Accept comma-notation in decimal input values #20

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
<name>Number Field</name>
<description>Dedicated number storage</description>
<repo type="github">https://github.com/symphonycms/numberfield</repo>
<url type="discuss">http://getsymphony.com/discuss/thread/144/</url>
<url type="discuss">https://www.getsymphony.com/discuss/thread/144/</url>
<url type="issues">https://github.com/symphonycms/numberfield/issues</url>
<types>
<type>Field Types</type>
</types>
<authors>
<author>
<name github="symphonycms" symphony="team">Symphony Team</name>
<website>http://getsymphony.com</website>
<website>https://www.getsymphony.com</website>
</author>
</authors>
<releases>
<release version="1.8.0" date="2018-11-01" min="2.5.x" max="2.x.x">
- Accept comma-notation in decimal input values ([#19](https://github.com/symphonycms/numberfield/issues/19))
- Added missing issues-url to extension.meta.xml
</release>
<release version="1.7.2" date="2017-08-23" min="2.5.x" max="2.x.x">
- PHP7 Compatibility for Symphony 2.x.x
</release>
Expand Down
16 changes: 12 additions & 4 deletions fields/field.number.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
}
Expand All @@ -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;
Expand Down