Skip to content
Permalink
Browse files

Add support for complex input type format.

  • Loading branch information...
markstory committed Jan 9, 2014
1 parent 293039c commit ee98664e4208816ba5f9cbb42f18b1831f328429
Showing with 45 additions and 5 deletions.
  1. +9 −4 Cake/View/Input/Radio.php
  2. +36 −1 Test/TestCase/View/Input/RadioTest.php
@@ -71,7 +71,12 @@ public function render($data) {
$options = (array)$data['options'];
$escape = $data['escape'];
foreach ($options as $val => $text) {
$radio = ['value' => $val];
if (is_int($val) && isset($text['text'], $text['value'])) {
$radio = $text;
$text = $radio['text'];
} else {
$radio = ['value' => $val, 'text' => $text];
}
$radio['name'] = $data['name'];
if (empty($radio['id'])) {
@@ -80,14 +85,14 @@ public function render($data) {
$labelAttrs = ['for' => $radio['id'], 'escape' => $escape];
$label = $this->_templates->format('label', [
'text' => $escape ? h($text) : $text,
'text' => $escape ? h($radio['text']) : $radio['text'],
'attrs' => $this->_templates->formatAttributes($labelAttrs),
]);
$input = $this->_templates->format('radio', [
'name' => $radio['name'],
'value' => $escape ? h($val) : $val,
'attrs' => $this->_templates->formatAttributes($radio, ['value', 'name']),
'value' => $escape ? h($radio['value']) : $radio['value'],
'attrs' => $this->_templates->formatAttributes($radio, ['name', 'value', 'text']),
]);
$opts[] = $this->_templates->format('radioContainer', [
@@ -69,8 +69,43 @@ public function testRenderSimple() {
$this->assertTags($result, $expected);
}
/**
* Test rendering inputs with the complex option form.
*
* @return void
*/
public function testRenderComplex() {
$this->markTestIncomplete();
$radio = new Radio($this->templates);
$data = [
'name' => 'Crayons[color]',
'options' => [
['value' => 'r', 'text' => 'Red', 'id' => 'my_id'],
['value' => 'b', 'text' => 'Black', 'id' => 'my_id_2', 'data-test' => 'test'],
]
];
$result = $radio->render($data);
$expected = [
['input' => [
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'r',
'id' => 'my_id'
]],
['label' => ['for' => 'my_id']],
'Red',
'/label',
['input' => [
'type' => 'radio',
'name' => 'Crayons[color]',
'value' => 'b',
'id' => 'my_id_2',
'data-test' => 'test'
]],
['label' => ['for' => 'my_id_2']],
'Black',
'/label',
];
$this->assertTags($result, $expected);
}
public function testRenderSelected() {

0 comments on commit ee98664

Please sign in to comment.
You can’t perform that action at this time.