From 506051f688431f6234edfb818c191f1d7a9df384 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 1 Oct 2015 21:46:21 -0400 Subject: [PATCH] Correct input generation for postgres numeric types. Numeric types in postgres are treated like decimals, except they can have no length, precision or scale components defined. IE does not accept 1.00000 as a valid step attribute so we'll default to any when we encounter decimal types with no length. Refs #7497 --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 12 ++++++++++++ lib/Cake/View/Helper/FormHelper.php | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 1058bc72f..535396b6b 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -353,6 +353,7 @@ class ValidateUser extends CakeTestModel { 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'), 'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'), + 'null_decimal' => array('type' => 'decimal', 'null' => false, 'length' => null), 'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'), 'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), @@ -2045,6 +2046,17 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Form->input('ValidateUser.null_decimal'); + $expected = array( + 'div' => array('class'), + 'label' => array('for'), + 'Null Decimal', + '/label', + 'input' => array('name', 'type' => 'number', 'step' => 'any', 'id'), + '/div', + ); + $this->assertTags($result, $expected); + $result = $this->Form->input('ValidateUser.ratio'); $expected = array( 'div' => array('class'), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 4f56e515b..3d1860688 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1209,10 +1209,10 @@ class FormHelper extends AppHelper { if ($options['type'] === 'number' && !isset($options['step']) ) { - if ($type === 'decimal') { + if ($type === 'decimal' && isset($fieldDef['length'])) { $decimalPlaces = substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1); $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces)); - } elseif ($type === 'float') { + } elseif ($type === 'float' || $type === 'decimal') { $options['step'] = 'any'; } }