From 34227c0f68014c0548e2e218059a3ef6c714177b Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 6 Dec 2007 15:55:44 +0000 Subject: [PATCH] "Fixes #3702, Radiobutton field ids conflict when using 2 models with the same fieldname" git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6122 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/form.php | 2 +- .../cases/libs/view/helpers/form.test.php | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index be877331b..570ce97ae 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -783,7 +783,7 @@ class FormHelper extends AppHelper { $optionsHere['checked'] = 'checked'; } $parsedOptions = $this->_parseAttributes(array_merge($attributes, $optionsHere), array('name', 'type', 'id'), '', ' '); - $tagName = Inflector::camelize($this->field() . '_'.Inflector::underscore($optValue)); + $tagName = Inflector::camelize($this->model() . '_' . $this->field() . '_'.Inflector::underscore($optValue)); if ($label) { $optTitle = sprintf($this->Html->tags['label'], $tagName, null, $optTitle); } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index a4971d0b5..2cb29ac1a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -638,50 +638,56 @@ class FormHelperTest extends CakeTestCase { function testRadio() { $result = $this->Form->radio('Model.field', array('option A')); - $this->assertPattern('/id="Field0"/', $result); - $this->assertNoPattern('/id="ModelField"/', $result); + $this->assertPattern('/id="ModelField0"/', $result); $this->assertNoPattern('/^
Field<\/legend>$/', $result); $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){1}/', $result); $result = $this->Form->radio('Model.field', array('option A', 'option B')); - $this->assertPattern('/id="Field0"/', $result); - $this->assertPattern('/id="Field1"/', $result); - $this->assertNoPattern('/id="ModelField"/', $result); + $this->assertPattern('/id="ModelField0"/', $result); + $this->assertPattern('/id="ModelField1"/', $result); $this->assertNoPattern('/checked="checked"/', $result); $this->assertPattern('/^
Field<\/legend>]+>(]+>]+>option [AB]<\/label>)+<\/fieldset>$/', $result); $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '
')); - $this->assertPattern('/id="Field0"/', $result); - $this->assertPattern('/id="Field1"/', $result); - $this->assertNoPattern('/id="ModelField"/', $result); + $this->assertPattern('/id="ModelField0"/', $result); + $this->assertPattern('/id="ModelField1"/', $result); $this->assertNoPattern('/checked="checked"/', $result); $this->assertPattern('/^
Field<\/legend>]+>]+>]+>option A<\/label>+]>]+>]+>option B<\/label><\/fieldset>$/', $result); $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1')); - $this->assertPattern('/id="Field1".*checked="checked"/', $result); - $this->assertPattern('/id="Field0"/', $result); + $this->assertPattern('/id="ModelField1".*checked="checked"/', $result); + $this->assertPattern('/id="ModelField0"/', $result); $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0')); - $this->assertPattern('/id="Field1"/', $result); - $this->assertPattern('/id="Field0".*checked="checked"/', $result); + $this->assertPattern('/id="ModelField1"/', $result); + $this->assertPattern('/id="ModelField0".*checked="checked"/', $result); $this->assertPattern('/(]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/', $result); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); - $expected = '
Legend title
'; + $expected = '
Legend title
'; $this->assertEqual($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); - $expected = '
'; + $expected = '
'; $this->assertEqual($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); - $expected = '
Legend titleUnsubscribeSubscribe
'; + $expected = '
Legend titleUnsubscribeSubscribe
'; $this->assertEqual($result, $expected); + $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); - $expected = '
UnsubscribeSubscribe
'; + $expected = '
UnsubscribeSubscribe
'; + $this->assertEqual($result, $expected); + + $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female')); + $expected = '
Gender
'; + $this->assertEqual($result, $expected); + + $result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female')); + $expected = '
Gender
'; $this->assertEqual($result, $expected); }