Browse Source

Use 'val' like other inputs.

Use the standard val option and add doc blocks.
mark_story 12 years ago
parent
commit
283a5b5b41
2 changed files with 18 additions and 3 deletions
  1. 17 2
      src/View/Input/Text.php
  2. 1 1
      tests/TestCase/View/Input/TextTest.php

+ 17 - 2
src/View/Input/Text.php

@@ -15,7 +15,11 @@
 namespace Cake\View\Input;
 
 /**
- * Text input class.
+ * Basic input class.
+ *
+ * This input class can be used to render basic simple
+ * input elements like hidden, text, email, tel and other
+ * types.
  */
 class Text {
 
@@ -38,16 +42,27 @@ class Text {
 /**
  * Render a text widget or other simple widget like email/tel/number.
  *
+ * This method accepts a number of keys:
+ *
+ * - `name` The name attribute.
+ * - `val` The value attribute.
+ * - `escape` Set to false to disable escaping on all attributes.
+ *
+ * Any other keys provided in $data will be converted into HTML attributes.
+ *
  * @param array $data The data to build an input with.
  * @return string
  */
 	public function render($data) {
 		$data += [
 			'name' => '',
-			'value' => null,
+			'val' => null,
 			'type' => 'text',
 			'escape' => true,
 		];
+		$data['value'] = $data['val'];
+		unset($data['val']);
+
 		return $this->_templates->format('input', [
 			'name' => $data['name'],
 			'type' => $data['type'],

+ 1 - 1
tests/TestCase/View/Input/TextTest.php

@@ -74,7 +74,7 @@ class TextTest extends TestCase {
 		$data = [
 			'name' => 'my_input',
 			'type' => 'email',
-			'value' => 'Some <value>'
+			'val' => 'Some <value>'
 		];
 		$result = $text->render($data);
 		$expected = [