Browse Source

Merge pull request #864 from dereuromark/2.3-radio-multiple-between

allow between to be an array of strings

Fixes #2859
Mark Story 13 years ago
parent
commit
bc4db91b51
2 changed files with 119 additions and 119 deletions
  1. 111 118
      lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. 8 1
      lib/Cake/View/Helper/FormHelper.php

+ 111 - 118
lib/Cake/Test/Case/View/Helper/FormHelperTest.php

@@ -35,13 +35,6 @@ App::uses('Router', 'Routing');
 class ContactTestController extends Controller {
 
 /**
- * name property
- *
- * @var string 'ContactTest'
- */
-	public $name = 'ContactTest';
-
-/**
  * uses property
  *
  * @var mixed null
@@ -58,13 +51,6 @@ class ContactTestController extends Controller {
 class Contact extends CakeTestModel {
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
  * useTable property
  *
  * @var bool false
@@ -72,13 +58,6 @@ class Contact extends CakeTestModel {
 	public $useTable = false;
 
 /**
- * name property
- *
- * @var string 'Contact'
- */
-	public $name = 'Contact';
-
-/**
  * Default schema
  *
  * @var array
@@ -171,13 +150,6 @@ class ContactTagsContact extends CakeTestModel {
 	public $useTable = false;
 
 /**
- * name property
- *
- * @var string 'Contact'
- */
-	public $name = 'ContactTagsContact';
-
-/**
  * Default schema
  *
  * @var array
@@ -216,13 +188,6 @@ class ContactNonStandardPk extends Contact {
 	public $primaryKey = 'pk';
 
 /**
- * name property
- *
- * @var string 'ContactNonStandardPk'
- */
-	public $name = 'ContactNonStandardPk';
-
-/**
  * schema method
  *
  * @return void
@@ -280,20 +245,6 @@ class UserForm extends CakeTestModel {
 	public $useTable = false;
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
- * name property
- *
- * @var string 'UserForm'
- */
-	public $name = 'UserForm';
-
-/**
  * hasMany property
  *
  * @var array
@@ -335,20 +286,6 @@ class OpenidUrl extends CakeTestModel {
 	public $useTable = false;
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
- * name property
- *
- * @var string 'OpenidUrl'
- */
-	public $name = 'OpenidUrl';
-
-/**
  * belongsTo property
  *
  * @var array
@@ -398,13 +335,6 @@ class OpenidUrl extends CakeTestModel {
 class ValidateUser extends CakeTestModel {
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
  * useTable property
  *
  * @var bool false
@@ -412,13 +342,6 @@ class ValidateUser extends CakeTestModel {
 	public $useTable = false;
 
 /**
- * name property
- *
- * @var string 'ValidateUser'
- */
-	public $name = 'ValidateUser';
-
-/**
  * hasOne property
  *
  * @var array
@@ -462,13 +385,6 @@ class ValidateUser extends CakeTestModel {
 class ValidateProfile extends CakeTestModel {
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
  * useTable property
  *
  * @var bool false
@@ -490,13 +406,6 @@ class ValidateProfile extends CakeTestModel {
 	);
 
 /**
- * name property
- *
- * @var string 'ValidateProfile'
- */
-	public $name = 'ValidateProfile';
-
-/**
  * hasOne property
  *
  * @var array
@@ -536,13 +445,6 @@ class ValidateProfile extends CakeTestModel {
 class ValidateItem extends CakeTestModel {
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
  * useTable property
  *
  * @var bool false
@@ -550,13 +452,6 @@ class ValidateItem extends CakeTestModel {
 	public $useTable = false;
 
 /**
- * name property
- *
- * @var string 'ValidateItem'
- */
-	public $name = 'ValidateItem';
-
-/**
  * schema property
  *
  * @var array
@@ -600,25 +495,12 @@ class ValidateItem extends CakeTestModel {
 class TestMail extends CakeTestModel {
 
 /**
- * primaryKey property
- *
- * @var string 'id'
- */
-	public $primaryKey = 'id';
-
-/**
  * useTable property
  *
  * @var bool false
  */
 	public $useTable = false;
 
-/**
- * name property
- *
- * @var string 'TestMail'
- */
-	public $name = 'TestMail';
 }
 
 /**
@@ -3575,6 +3457,51 @@ class FormHelperTest extends CakeTestCase {
 			'/fieldset'
 		);
 		$this->assertTags($result, $expected);
+
+		$result = $this->Form->radio(
+			'Model.field',
+			array('option A', 'option B', 'option C'),
+			array('separator' => '--separator--', 'between' => array('between A', 'between B', 'between C'))
+		);
+
+		$expected = array(
+			'fieldset' => array(),
+			'legend' => array(),
+			'Field',
+			'/legend',
+			'input' => array(
+				'type' => 'hidden', 'name' => 'data[Model][field]',
+				'value' => '', 'id' => 'ModelField_'
+			),
+			array('input' => array(
+				'type' => 'radio', 'name' => 'data[Model][field]',
+				'value' => '0', 'id' => 'ModelField0'
+			)),
+			array('label' => array('for' => 'ModelField0')),
+			'option A',
+			'/label',
+			'between A',
+			'--separator--',
+			array('input' => array(
+				'type' => 'radio', 'name' => 'data[Model][field]',
+				'value' => '1', 'id' => 'ModelField1'
+			)),
+			array('label' => array('for' => 'ModelField1')),
+			'option B',
+			'/label',
+			'between B',
+			'--separator--',
+			array('input' => array(
+				'type' => 'radio', 'name' => 'data[Model][field]',
+				'value' => '2', 'id' => 'ModelField2'
+			)),
+			array('label' => array('for' => 'ModelField2')),
+			'option C',
+			'/label',
+			'between C',
+			'/fieldset'
+		);
+		$this->assertTags($result, $expected);
 	}
 
 /**
@@ -3729,6 +3656,72 @@ class FormHelperTest extends CakeTestCase {
 			'/fieldset'
 		);
 		$this->assertTags($result, $expected);
+
+		$result = $this->Form->input('Model.field', array(
+			'options' => array('1' => 'first', '2' => 'second'),
+			'type' => 'radio',
+			'before' => '--before--',
+			'after' => '--after--',
+			'separator' => '--separator--',
+			'between' => array('--between first--', '--between second--')
+		));
+
+		$expected = array(
+			'div' => array('class' => 'input radio'),
+			'--before--',
+			'fieldset' => array(),
+			'legend' => array(),
+			'Field',
+			'/legend',
+			array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
+			array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
+			array('label' => array('for' => 'ModelField1')),
+			'first',
+			'/label',
+			'--between first--',
+			'--separator--',
+			array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
+			array('label' => array('for' => 'ModelField2')),
+			'second',
+			'/label',
+			'--between second--',
+			'/fieldset',
+			'--after--',
+			'/div'
+		);
+		$this->assertTags($result, $expected);
+
+		$result = $this->Form->input('Model.field', array(
+			'options' => array('1' => 'first', '2' => 'second'),
+			'type' => 'radio',
+			'before' => '--before--',
+			'after' => '--after--',
+			'separator' => '--separator--',
+			'between' => array('--between first--')
+		));
+
+		$expected = array(
+			'div' => array('class' => 'input radio'),
+			'--before--',
+			'fieldset' => array(),
+			'legend' => array(),
+			'Field',
+			'/legend',
+			array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
+			array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
+			array('label' => array('for' => 'ModelField1')),
+			'first',
+			'/label',
+			'--between first--',
+			'--separator--',
+			array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
+			array('label' => array('for' => 'ModelField2')),
+			'second',
+			'/label',
+			'/fieldset',
+			'--after--',
+			'/div'
+		);
 	}
 
 /**

+ 8 - 1
lib/Cake/View/Helper/FormHelper.php

@@ -1417,7 +1417,8 @@ class FormHelper extends AppHelper {
  * ### Attributes:
  *
  * - `separator` - define the string in between the radio buttons
- * - `between` - the string between legend and input set
+ * - `between` - the string between legend and input set or array of strings to insert
+ *    strings between each input block
  * - `legend` - control whether or not the widget set has a fieldset & legend
  * - `value` - indicate a value that is should be checked
  * - `label` - boolean to indicate whether or not labels for widgets show be displayed
@@ -1506,6 +1507,9 @@ class FormHelper extends AppHelper {
 			if ($label) {
 				$optTitle = $this->Html->useTag('label', $tagName, '', $optTitle);
 			}
+			if (is_array($between)) {
+				$optTitle .= array_shift($between);
+			}
 			$allOptions = array_merge($attributes, $optionsHere);
 			$out[] = $this->Html->useTag('radio', $attributes['name'], $tagName,
 				array_diff_key($allOptions, array('name' => '', 'type' => '', 'id' => '')),
@@ -1523,6 +1527,9 @@ class FormHelper extends AppHelper {
 		}
 		$out = $hidden . implode($separator, $out);
 
+		if (is_array($between)) {
+			$between = '';
+		}
 		if ($legend) {
 			$out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $between . $out);
 		}