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
This commit is contained in:
gwoo 2007-09-07 01:22:03 +00:00
parent 3eaa019625
commit ed6b0d7649
3 changed files with 15 additions and 8 deletions

View file

@ -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, '', ' ');

View file

@ -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()]);

View file

@ -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() {