From ed6b0d7649f387ffd8ca345652750f15eb9b5b5e Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 7 Sep 2007 01:22:03 +0000 Subject: [PATCH] fixes #3184 FormHelper::radio() values, fixes #3156 FormHelper::create() action, fixes #3097 FormHelper::label() localization text. Thank you for the patches and tests. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5619 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/form.php | 11 +++++------ cake/libs/view/helpers/html.php | 4 ++-- cake/tests/cases/libs/view/helpers/form.test.php | 8 ++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index b762c649a..331f3dcca 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -147,7 +147,7 @@ class FormHelper extends AppHelper { if (empty($options['url']) || is_array($options['url'])) { $options = (array)$options; - if (!empty($model) && $model != $defaultModel) { + if (!isset($this->params['controller']) && !empty($model) && $model != $defaultModel) { $controller = Inflector::underscore(Inflector::pluralize($model)); } else { $controller = Inflector::underscore($this->params['controller']); @@ -373,7 +373,9 @@ class FormHelper extends AppHelper { } else { $labelFor = $this->domId($fieldName); } - + if(!empty($text)) { + $text = __($text, true); + } return $this->output(sprintf($this->Html->tags['label'], $labelFor, $this->_parseAttributes($attributes), $text)); } /** @@ -582,9 +584,6 @@ class FormHelper extends AppHelper { $labelText = $label; } - if (!empty($labelText)) { - $labelText = __($labelText, true); - } if($options['type'] != 'radio') { $out = $this->label(null, $labelText, $labelAttributes); } else { @@ -753,7 +752,7 @@ class FormHelper extends AppHelper { foreach ($options as $optValue => $optTitle) { $optionsHere = array('value' => $optValue); - if (!empty($value) && $optValue == $value) { + if (isset($value) && $optValue == $value) { $optionsHere['checked'] = 'checked'; } $parsedOptions = $this->_parseAttributes(array_merge($attributes, $optionsHere), null, '', ' '); diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 7c3ad55d4..b983fac69 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -623,10 +623,10 @@ class HtmlHelper extends AppHelper { * Returns value of $fieldName. False if the tag does not exist. * * @deprecated 1.2.0.5147 - * @see FormHelper::errors + * @see Helper::value */ function tagValue($fieldName) { - trigger_error(sprintf(__('Method tagValue() is deprecated in %s: see HtmlHelper::value', true), get_class($this)), E_USER_NOTICE); + trigger_error(sprintf(__('Method tagValue() is deprecated in %s: see Helper::value', true), get_class($this)), E_USER_NOTICE); $this->setFormTag($fieldName); if (isset($this->data[$this->model()][$this->field()])) { return h($this->data[$this->model()][$this->field()]); diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 8344370d7..c6e2a918e 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -454,6 +454,14 @@ class FormHelperTest extends CakeTestCase { $this->assertPattern('/id="Field1"/', $result); $this->assertNoPattern('/id="ModelField"/', $result); $this->assertNoPattern('/checked="checked"/', $result); + + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), null, array('value' => '1')); + $this->assertPattern('/id="Field1".*checked="checked"/', $result); + $this->assertPattern('/id="Field0"/', $result); + + $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), null, array('value' => '0')); + $this->assertPattern('/id="Field1"/', $result); + $this->assertPattern('/id="Field0".*checked="checked"/', $result); } function testSelect() {