Merge pull request #538 from mcammaert/2.1

Merging input defaults with passed options to preserve nested keys
This commit is contained in:
José Lorenzo Rodríguez 2012-02-29 09:09:11 -08:00
commit 96f73d6392
2 changed files with 15 additions and 3 deletions

View file

@ -6528,8 +6528,8 @@ class FormHelperTest extends CakeTestCase {
*/
public function testCreateWithInputDefaults() {
$this->Form->create('User', array(
'inputDefaults' => array('div' => false, 'label' => false)
));
'inputDefaults' => array('div' => false, 'label' => false, 'error' => array('attributes'=>array('wrap' => 'small', 'class' => 'error')))
));
$result = $this->Form->input('username');
$expected = array(
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername')
@ -6544,6 +6544,18 @@ class FormHelperTest extends CakeTestCase {
'/div'
);
$this->assertTags($result, $expected);
$User = ClassRegistry::getObject('User');
$User->validationErrors['username'] = array('empty');
$result = $this->Form->input('username', array('div' => true, 'label' => 'username', 'error' => array('empty' => __('Required'))));
$expected = array(
'div' => array('class' => 'input text error'),
'label' => array('for' => 'UserUsername'), 'username', '/label',
'input' => array('class' => 'form-error', 'type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
'small' => array('class' => 'error'), 'Required', '/small',
'/div'
);
$this->assertTags($result, $expected);
}
/**

View file

@ -946,7 +946,7 @@ class FormHelper extends AppHelper {
public function input($fieldName, $options = array()) {
$this->setEntity($fieldName);
$options = array_merge(
$options = Set::merge(
array('before' => null, 'between' => null, 'after' => null, 'format' => null),
$this->_inputDefaults,
$options