From 333f36585b27072d40f8b0d5e7b464b0c50e185a Mon Sep 17 00:00:00 2001 From: Dean Sofer Date: Tue, 26 Jul 2011 01:39:56 -0700 Subject: [PATCH 1/3] Added `'integer' => 'number'` for HTML5 Located in $map in the `FormHelper::input()` method. This means that if a field input is related to an integer column in the database, it will show up as a number input in the HTML5 form (where supported) yet gracefully degrade. --- lib/Cake/View/Helper/FormHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index a4be6890a..3bdd5d31c 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -917,7 +917,8 @@ class FormHelper extends AppHelper { 'string' => 'text', 'datetime' => 'datetime', 'boolean' => 'checkbox', 'timestamp' => 'datetime', 'text' => 'textarea', 'time' => 'time', - 'date' => 'date', 'float' => 'text' + 'date' => 'date', 'float' => 'text', + 'integer' => 'number' ); if (isset($this->map[$type])) { From 804e88b092f38f95d4b23ad72a7f34c4f57b969e Mon Sep 17 00:00:00 2001 From: Dean Sofer Date: Tue, 26 Jul 2011 02:19:41 -0700 Subject: [PATCH 2/3] Added test for HTML5 `FormHelper::input()` integer to number in $map --- .../Test/Case/View/Helper/FormHelperTest.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 1a61b6719..a1f15255a 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -97,7 +97,8 @@ class Contact extends CakeTestModel { 'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null), + 'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null) ); /** @@ -886,6 +887,36 @@ class FormHelperTest extends CakeTestCase { '/div' ); } + +/** + * Tests correct generation of text fields for double and float fields + * + * @access public + * @return void + */ + public function testTextFieldTypeNumberGenerationForIntegers() { + $model = ClassRegistry::getObject('Contact'); + $model->setSchema(array('foo' => array( + 'type' => 'integer', + 'null' => false, + 'default' => null, + 'length' => null + ))); + + $this->Form->create('Contact'); + $result = $this->Form->input('foo'); + $expected = array( + 'div' => array('class' => 'input text'), + 'label' => array('for' => 'ContactFoo'), + 'Foo', + '/label', + array('input' => array( + 'type' => 'number', 'name' => 'data[Contact][foo]', + 'id' => 'ContactFoo' + )), + '/div' + ); + } /** * testFormSecurityMultipleFields method From 2ef17ec0a7b1cd8349402830075e0156ec631272 Mon Sep 17 00:00:00 2001 From: Dean Sofer Date: Wed, 27 Jul 2011 15:15:31 -0700 Subject: [PATCH 3/3] Additional tweak to FormHelper::input(), make float types use the number input --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 3bdd5d31c..7c9bc4062 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -917,7 +917,7 @@ class FormHelper extends AppHelper { 'string' => 'text', 'datetime' => 'datetime', 'boolean' => 'checkbox', 'timestamp' => 'datetime', 'text' => 'textarea', 'time' => 'time', - 'date' => 'date', 'float' => 'text', + 'date' => 'date', 'float' => 'number', 'integer' => 'number' );