Skip to content
This repository
Browse code

Making magic select not override magic hidden. Tests added.

Fixes #782
  • Loading branch information...
commit e41e89cd2a6d7e5bd71911fab14e756648126f4c 1 parent bd6e16b
Mark Story authored June 04, 2010
2  cake/libs/view/helpers/form.php
@@ -740,7 +740,7 @@ function input($fieldName, $options = array()) {
740 740
 					$options['type'] = 'hidden';
741 741
 				}
742 742
 			}
743  
-			if (preg_match('/_id$/', $fieldKey)) {
  743
+			if (preg_match('/_id$/', $fieldKey) && $options['type'] !== 'hidden') {
744 744
 				$options['type'] = 'select';
745 745
 			}
746 746
 
23  cake/tests/cases/libs/view/helpers/form.test.php
@@ -2119,6 +2119,29 @@ function testInputSelectType() {
2119 2119
 	}
2120 2120
 
2121 2121
 /**
  2122
+ * test that input() and a non standard primary key makes a hidden input by default.
  2123
+ *
  2124
+ * @return void
  2125
+ */
  2126
+	function testInputWithNonStandardPrimaryKeyMakesHidden() {
  2127
+		$this->Form->create('User');
  2128
+		$this->Form->fieldset = array(
  2129
+			'User' => array(
  2130
+				'fields' => array(
  2131
+					'model_id' => array('type' => 'integer')
  2132
+				),
  2133
+				'validates' => array(),
  2134
+				'key' => 'model_id'
  2135
+			)
  2136
+		);
  2137
+		$result = $this->Form->input('model_id');
  2138
+		$expected = array(
  2139
+			'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'),
  2140
+		);
  2141
+		$this->assertTags($result, $expected);
  2142
+	}
  2143
+
  2144
+/**
2122 2145
  * test that overriding the magic select type widget is possible
2123 2146
  *
2124 2147
  * @return void

0 notes on commit e41e89c

Please sign in to comment.
Something went wrong with that request. Please try again.