diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index aaf4ae780..85285f7e3 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -353,6 +353,8 @@ 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'), + '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' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); @@ -1916,6 +1918,28 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Form->input('ValidateUser.ratio'); + $expected = array( + 'div' => array('class'), + 'label' => array('for'), + 'Ratio', + '/label', + 'input' => array('name', 'type' => 'number', 'step' => '0.000001', 'id'), + '/div', + ); + $this->assertTags($result, $expected); + + $result = $this->Form->input('ValidateUser.population'); + $expected = array( + 'div' => array('class'), + 'label' => array('for'), + 'Population', + '/label', + 'input' => array('name', 'type' => 'number', 'step' => '1', 'id'), + '/div', + ); + $this->assertTags($result, $expected); + $result = $this->Form->input('Contact.email', array('id' => 'custom')); $expected = array( 'div' => array('class' => 'input email'), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 5b4cdc6e4..b690c4ac0 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1173,7 +1173,8 @@ class FormHelper extends AppHelper { !isset($options['step']) ) { if ($type === 'decimal') { - $options['step'] = pow(10, -1 * substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1)); + $decimalPlaces = substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1); + $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces)); } elseif ($type === 'float') { $options['step'] = 'any'; }