mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Merge pull request #383 from shama/patch-checkbox-hiddenField
Ability to set hiddenField value with FormHelper::checkbox
This commit is contained in:
commit
99e9f62305
2 changed files with 32 additions and 8 deletions
|
@ -4512,16 +4512,16 @@ class FormHelperTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the hidden input for checkboxes can be removed/omitted from the output.
|
* Test that the hidden input for checkboxes can be omitted or set to a
|
||||||
|
* specific value.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCheckboxHiddenFieldOmission() {
|
public function testCheckboxHiddenField() {
|
||||||
$result = $this->Form->input('UserForm.something', array(
|
$result = $this->Form->input('UserForm.something', array(
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'hiddenField' => false
|
'hiddenField' => false
|
||||||
)
|
));
|
||||||
);
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'input checkbox'),
|
'div' => array('class' => 'input checkbox'),
|
||||||
array('input' => array(
|
array('input' => array(
|
||||||
|
@ -4534,6 +4534,28 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->input('UserForm.something', array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'value' => 'Y',
|
||||||
|
'hiddenField' => 'N',
|
||||||
|
));
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input checkbox'),
|
||||||
|
array('input' => array(
|
||||||
|
'type' => 'hidden', 'name' => 'data[UserForm][something]',
|
||||||
|
'value' => 'N', 'id' => 'UserFormSomething_'
|
||||||
|
)),
|
||||||
|
array('input' => array(
|
||||||
|
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
||||||
|
'value' => 'Y', 'id' => 'UserFormSomething'
|
||||||
|
)),
|
||||||
|
'label' => array('for' => 'UserFormSomething'),
|
||||||
|
'Something',
|
||||||
|
'/label',
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1232,8 +1232,10 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
if ($options['hiddenField']) {
|
if ($options['hiddenField']) {
|
||||||
$hiddenOptions = array(
|
$hiddenOptions = array(
|
||||||
'id' => $options['id'] . '_', 'name' => $options['name'],
|
'id' => $options['id'] . '_',
|
||||||
'value' => '0', 'secure' => false
|
'name' => $options['name'],
|
||||||
|
'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'),
|
||||||
|
'secure' => false
|
||||||
);
|
);
|
||||||
if (isset($options['disabled']) && $options['disabled'] == true) {
|
if (isset($options['disabled']) && $options['disabled'] == true) {
|
||||||
$hiddenOptions['disabled'] = 'disabled';
|
$hiddenOptions['disabled'] = 'disabled';
|
||||||
|
|
Loading…
Add table
Reference in a new issue