Adding fix for Ticket #1005

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3105 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-06-15 12:12:46 +00:00
parent a1ee0d93c4
commit ae3a8d0f9e

View file

@ -255,23 +255,33 @@ class HtmlHelper extends Helper {
function checkbox($fieldName, $title = null, $htmlAttributes = null, $return = false) { function checkbox($fieldName, $title = null, $htmlAttributes = null, $return = false) {
$value = $this->tagValue($fieldName); $value = $this->tagValue($fieldName);
$notCheckedValue = 0; $notCheckedValue = 0;
if (isset($htmlAttributes['value'])) {
$htmlAttributes['checked']=($htmlAttributes['value'] == $value) ? 'checked' : null;
if ($htmlAttributes['checked'] == '0') { if (isset($htmlAttributes['checked'])) {
if ($htmlAttributes['checked'] == 'checked' || intval($htmlAttributes['checked']) === 1 || $htmlAttributes['checked'] === true) {
$htmlAttributes['checked'] = 'checked';
} else {
$htmlAttributes['checked'] = null;
$notCheckedValue = -1; $notCheckedValue = -1;
} }
} else { } else {
$model = new $this->model; if (isset($htmlAttributes['value'])) {
$db =& ConnectionManager::getDataSource($model->useDbConfig); $htmlAttributes['checked'] = ($htmlAttributes['value'] == $value) ? 'checked' : null;
$value = $db->boolean($value);
$htmlAttributes['checked'] = $value ? 'checked' : null; if ($htmlAttributes['checked'] == '0') {
$htmlAttributes['value'] = 1; $notCheckedValue = -1;
}
} else {
$model = new $this->model;
$db =& ConnectionManager::getDataSource($model->useDbConfig);
$value = $db->boolean($value);
$htmlAttributes['checked'] = $value ? 'checked' : null;
$htmlAttributes['value'] = 1;
}
} }
if (!isset($htmlAttributes['id'])) { if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field); $htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
} }
$output = $this->hidden($fieldName, array('value' => $notCheckedValue), true); $output = $this->hidden($fieldName, array('value' => $notCheckedValue, 'id' => $htmlAttributes['id'] . '_'), true);
$output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' ')); $output .= sprintf($this->tags['checkbox'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, '', ' '));
return $this->output($output, $return); return $this->output($output, $return);
} }