From a9ae7fd5bbae6f7c373e65febda1eff375edd9a1 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 20 Apr 2015 18:31:00 +0200 Subject: [PATCH 1/5] Fix year form field when magic input wrapper is used. s --- lib/Cake/View/Helper/FormHelper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 880f5fd3f..b9a49614b 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2213,6 +2213,11 @@ class FormHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::year */ public function year($fieldName, $minYear = null, $maxYear = null, $attributes = array()) { + if (is_array($minYear)) { + $attributes = $minYear; + $minYear = null; + } + $attributes += array('empty' => true, 'value' => null); if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) { if (is_array($value)) { From c71a478876b606f800e509f0e9dbdbac78b5c4fb Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 20 Apr 2015 18:38:19 +0200 Subject: [PATCH 2/5] Add test case. --- .../Test/Case/View/Helper/FormHelperTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 4b6cfb7e1..598690d30 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -7430,6 +7430,53 @@ class FormHelperTest extends CakeTestCase { $this->assertNotContains('value="' . date('d') . '" selected="selected"', $result); } +/** + * testInputDate method + * + * Test various inputs with type date and different option attributes. + * + * @return void + */ + public function testInputDateOptions() { + $this->Form->create('User'); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'day', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'month', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'year', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'year', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + } + /** * testInputDateMaxYear method * From 3ba430835648f5f98db1e054422b2d01b18d7e6f Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 20 Apr 2015 18:39:54 +0200 Subject: [PATCH 3/5] Use hour as field name. --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 598690d30..bd0dbb2c8 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -7470,7 +7470,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->input('date', array( 'label' => false, - 'type' => 'year', + 'type' => 'hour', 'class' => 'form-control' ) ); From 8cdf222cc045accc661759be3894bb1a8f492dfc Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 20 Apr 2015 22:04:33 +0200 Subject: [PATCH 4/5] Also fix hour() --- lib/Cake/View/Helper/FormHelper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index b9a49614b..032040c99 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2315,6 +2315,11 @@ class FormHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::hour */ public function hour($fieldName, $format24Hours = false, $attributes = array()) { + if (is_array($format24Hours)) { + $attributes = $format24Hours; + $format24Hours = null; + } + $attributes += array('empty' => true, 'value' => null); $attributes = $this->_dateTimeSelected('hour', $fieldName, $attributes); From c31fcd6f3993ad12d366567e03c357358bde40e3 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Tue, 21 Apr 2015 14:32:34 +0200 Subject: [PATCH 5/5] Correct default value to false. --- 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 032040c99..2a9f5be6c 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2317,7 +2317,7 @@ class FormHelper extends AppHelper { public function hour($fieldName, $format24Hours = false, $attributes = array()) { if (is_array($format24Hours)) { $attributes = $format24Hours; - $format24Hours = null; + $format24Hours = false; } $attributes += array('empty' => true, 'value' => null);