Permalink
Browse files

Fixing Form::dateTime() for GET forms. Tests added. Fixes #522

  • Loading branch information...
1 parent fdd8a51 commit 3503872ab81dc69344554312006d8e29c73bc45d @markstory markstory committed Apr 2, 2010
Showing with 23 additions and 1 deletion.
  1. +6 −1 cake/libs/view/helpers/form.php
  2. +17 −0 cake/tests/cases/libs/view/helpers/form.test.php
View
7 cake/libs/view/helpers/form.php
@@ -1905,7 +1905,12 @@ function _name($options = array(), $field = null, $key = 'name') {
if (is_array($options) && isset($options[$key])) {
return $options;
}
- $name = $this->field();
+
+ $view = ClassRegistry::getObject('view');
+ $name = $view->field;
+ if (!empty($view->fieldSuffix)) {
+ $name .= '[' . $view->fieldSuffix . ']';
+ }
if (is_array($options)) {
$options[$key] = $name;
View
17 cake/tests/cases/libs/view/helpers/form.test.php
@@ -5298,6 +5298,23 @@ function testGetFormCreate() {
}
/**
+ * test that datetime() works with GET style forms.
+ *
+ * @return void
+ */
+ function testDateTimeWithGetForms() {
+ extract($this->dateRegex);
+ $this->Form->create('Contact', array('type' => 'get'));
+ $result = $this->Form->datetime('created');
+
+ $this->assertPattern('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
+ $this->assertPattern('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
+ $this->assertPattern('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
+ $this->assertPattern('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
+ $this->assertPattern('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
+ $this->assertPattern('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
+ }
+/**
* testEditFormWithData method
*
* test auto populating form elements from submitted data.

0 comments on commit 3503872

Please sign in to comment.