Skip to content

Commit

Permalink
Setting of step for decimal field based on precision.
Browse files Browse the repository at this point in the history
  • Loading branch information
uzyn committed Sep 29, 2013
1 parent 091658a commit 4806d09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -1883,7 +1883,7 @@ public function testInput() {
'label' => array('for'),
'Cost Decimal',
'/label',
'input' => array('name', 'type' => 'number', 'id'),
'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
'/div',
);
$this->assertTags($result, $expected);
Expand Down
7 changes: 5 additions & 2 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1160,10 +1160,13 @@ protected function _magicOptions($options) {
}
if (
$options['type'] === 'number' &&
$type === 'float' &&
!isset($options['step'])
) {
$options['step'] = 'any';
if ($type === 'decimal') {
$options['step'] = pow(10, -1 * substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1));
} elseif ($type === 'float') {
$options['step'] = 'any';
}
}
}

Expand Down

0 comments on commit 4806d09

Please sign in to comment.