Setting of step for decimal field based on precision.

This commit is contained in:
U-Zyn Chua 2013-09-29 22:44:50 +08:00
parent 091658a752
commit 4806d09d7e
2 changed files with 6 additions and 3 deletions

View file

@ -1883,7 +1883,7 @@ class FormHelperTest extends CakeTestCase {
'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);

View file

@ -1160,10 +1160,13 @@ class FormHelper extends AppHelper {
}
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';
}
}
}