mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Allow empty values in checkboxes.
Allow the checkbox value attribute to be empty. This is required to make checkboxes with a value of 0. Fixes #2717
This commit is contained in:
parent
b73cbf4a12
commit
605351d0c9
2 changed files with 30 additions and 4 deletions
|
@ -5836,6 +5836,35 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a checkbox can have 0 for the value and 1 for the hidden input.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckboxZeroValue() {
|
||||
$result = $this->Form->input('User.get_spam', array(
|
||||
'type' => 'checkbox',
|
||||
'value' => '0',
|
||||
'hiddenField' => '1',
|
||||
));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input checkbox'),
|
||||
array('input' => array(
|
||||
'type' => 'hidden', 'name' => 'data[User][get_spam]',
|
||||
'value' => '1', 'id' => 'UserGetSpam_'
|
||||
)),
|
||||
array('input' => array(
|
||||
'type' => 'checkbox', 'name' => 'data[User][get_spam]',
|
||||
'value' => '0', 'id' => 'UserGetSpam'
|
||||
)),
|
||||
'label' => array('for' => 'UserGetSpam'),
|
||||
'Get Spam',
|
||||
'/label',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDateTime method
|
||||
*
|
||||
|
|
|
@ -1402,14 +1402,11 @@ class FormHelper extends AppHelper {
|
|||
unset($options['default']);
|
||||
}
|
||||
|
||||
$options += array('required' => false);
|
||||
$options += array('value' => 1, 'required' => false);
|
||||
$options = $this->_initInputField($fieldName, $options) + array('hiddenField' => true);
|
||||
$value = current($this->value($valueOptions));
|
||||
$output = '';
|
||||
|
||||
if (empty($options['value'])) {
|
||||
$options['value'] = 1;
|
||||
}
|
||||
if (
|
||||
(!isset($options['checked']) && !empty($value) && $value == $options['value']) ||
|
||||
!empty($options['checked'])
|
||||
|
|
Loading…
Add table
Reference in a new issue