Skip to content
Permalink
Browse files

Added FormHelper::inputDefaults setter/getter method

  • Loading branch information...
tigrang committed May 20, 2012
1 parent 2ad406a commit 1d77ad393c5ab0891637b2efe3bfe520bddbc866
Showing with 80 additions and 0 deletions.
  1. +62 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +18 −0 lib/Cake/View/Helper/FormHelper.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);
}
}
@@ -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;
}
}
}

0 comments on commit 1d77ad3

Please sign in to comment.
You can’t perform that action at this time.