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'), 'label' => array('for'),
'Cost Decimal', 'Cost Decimal',
'/label', '/label',
'input' => array('name', 'type' => 'number', 'id'), 'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
'/div', '/div',
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);

View file

@ -1160,10 +1160,13 @@ class FormHelper extends AppHelper {
} }
if ( if (
$options['type'] === 'number' && $options['type'] === 'number' &&
$type === 'float' &&
!isset($options['step']) !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';
}
} }
} }