Fixing issues with HTML5 number inputs and float columns.

For float columns, the default step value is 'any'
Fixes #1907
This commit is contained in:
Mark Story 2011-08-18 22:31:00 -04:00
parent 0e21093268
commit 46c07add3f
2 changed files with 33 additions and 6 deletions

View file

@ -859,7 +859,7 @@ class FormHelperTest extends CakeTestCase {
}
/**
* Tests correct generation of text fields for double and float fields
* Tests correct generation of number fields for double and float fields
*
* @access public
* @return void
@ -876,20 +876,39 @@ class FormHelperTest extends CakeTestCase {
$this->Form->create('Contact');
$result = $this->Form->input('foo');
$expected = array(
'div' => array('class' => 'input text'),
'div' => array('class' => 'input number'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][foo]',
'id' => 'ContactFoo'
'type' => 'number',
'name' => 'data[Contact][foo]',
'id' => 'ContactFoo',
'step' => 'any'
)),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('foo', array('step' => 0.5));
$expected = array(
'div' => array('class' => 'input number'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
array('input' => array(
'type' => 'number',
'name' => 'data[Contact][foo]',
'id' => 'ContactFoo',
'step' => '0.5'
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* Tests correct generation of text fields for double and float fields
* Tests correct generation of number fields for integer fields
*
* @access public
* @return void
@ -906,7 +925,7 @@ class FormHelperTest extends CakeTestCase {
$this->Form->create('Contact');
$result = $this->Form->input('foo');
$expected = array(
'div' => array('class' => 'input text'),
'div' => array('class' => 'input number'),
'label' => array('for' => 'ContactFoo'),
'Foo',
'/label',
@ -916,6 +935,7 @@ class FormHelperTest extends CakeTestCase {
)),
'/div'
);
$this->assertTags($result, $expected);
}
/**

View file

@ -939,6 +939,13 @@ class FormHelper extends AppHelper {
if ($fieldKey == $primaryKey) {
$options['type'] = 'hidden';
}
if (
$options['type'] === 'number' &&
$type === 'float' &&
!isset($options['step'])
) {
$options['step'] = 'any';
}
}
if (preg_match('/_id$/', $fieldKey) && $options['type'] !== 'hidden') {
$options['type'] = 'select';