Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added FormHelper::inputDefaults setter/getter method

  • Loading branch information...
commit 1d77ad393c5ab0891637b2efe3bfe520bddbc866 1 parent 2ad406a
@tigrang tigrang authored
View
62 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -7939,4 +7939,66 @@ public function testRequiredOnUpdate() {
);
$this->assertTags($result, $expected);
}
+
+/**
+ * Test inputDefaults setter and getter
+ *
+ * @return void
+ */
+ public function testInputDefaults() {
+ $this->Form->create('Contact');
+
+ $this->Form->inputDefaults(array(
+ 'label' => false,
+ 'div' => array(
+ 'style' => 'color: #000;'
+ )
+ ));
+ $result = $this->Form->input('Contact.field1');
+ $expected = array(
+ 'div' => array('class' => 'input text', 'style' => 'color: #000;'),
+ 'input' => array(
+ 'type' => 'text', 'name' => 'data[Contact][field1]',
+ 'id' => 'ContactField1'
+ ),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
+ $this->Form->inputDefaults(array(
+ 'div' => false,
+ 'label' => 'Label',
+ ));
+ $result = $this->Form->input('Contact.field1');
+ $expected = array(
+ 'label' => array('for' => 'ContactField1'),
+ 'Label',
+ '/label',
+ 'input' => array(
+ 'type' => 'text', 'name' => 'data[Contact][field1]',
+ 'id' => 'ContactField1'
+ ),
+ );
+ $this->assertTags($result, $expected);
+
+ $this->Form->inputDefaults(array(
+ 'label' => false,
+ ), true);
+ $result = $this->Form->input('Contact.field1');
+ $expected = array(
+ 'input' => array(
+ 'type' => 'text', 'name' => 'data[Contact][field1]',
+ 'id' => 'ContactField1'
+ ),
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Form->inputDefaults();
+ $expected = array(
+ 'div' => false,
+ 'label' => false,
+ );
+ $this->assertEqual($result, $expected);
+ }
+
}
View
18 lib/Cake/View/Helper/FormHelper.php
@@ -2583,4 +2583,22 @@ protected function _initInputField($field, $options = array()) {
return $result;
}
+/**
+ * Set/Get inputDefaults for form elements
+ *
+ * @param array $defaults New default values
+ * @param boolean Merge with current defaults
+ * @return mixed array|void Current inputDefaults
+ */
+ public function inputDefaults($defaults = null, $merge = false) {
+ if (is_null($defaults)) {
+ return $this->_inputDefaults;
+ }
+ if ($merge) {
+ $this->_inputDefaults = array_merge($this->_inputDefaults, (array)$defaults);
+ } else {
+ $this->_inputDefaults = (array)$defaults;
+ }
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.