Commit a1612f5d by Qiang Xue

Fixes #1362: added itemOptions to Html::radioList and checkboxList.

parent 8307075f
...@@ -739,6 +739,7 @@ class BaseHtml ...@@ -739,6 +739,7 @@ class BaseHtml
* - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. * - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true.
* This option is ignored if `item` option is set. * This option is ignored if `item` option is set.
* - separator: string, the HTML code that separates items. * - separator: string, the HTML code that separates items.
* - itemOptions: array, the options for generating the radio button tag using [[checkbox()]].
* - item: callable, a callback that can be used to customize the generation of the HTML code * - item: callable, a callback that can be used to customize the generation of the HTML code
* corresponding to a single item in $items. The signature of this callback must be: * corresponding to a single item in $items. The signature of this callback must be:
* *
...@@ -758,6 +759,7 @@ class BaseHtml ...@@ -758,6 +759,7 @@ class BaseHtml
} }
$formatter = isset($options['item']) ? $options['item'] : null; $formatter = isset($options['item']) ? $options['item'] : null;
$itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
$encode = !isset($options['encode']) || $options['encode']; $encode = !isset($options['encode']) || $options['encode'];
$lines = []; $lines = [];
$index = 0; $index = 0;
...@@ -768,10 +770,10 @@ class BaseHtml ...@@ -768,10 +770,10 @@ class BaseHtml
if ($formatter !== null) { if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value); $lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else { } else {
$lines[] = static::checkbox($name, $checked, [ $lines[] = static::checkbox($name, $checked, array_merge($itemOptions, [
'value' => $value, 'value' => $value,
'label' => $encode ? static::encode($label) : $label, 'label' => $encode ? static::encode($label) : $label,
]); ]));
} }
$index++; $index++;
} }
...@@ -786,7 +788,7 @@ class BaseHtml ...@@ -786,7 +788,7 @@ class BaseHtml
$separator = isset($options['separator']) ? $options['separator'] : "\n"; $separator = isset($options['separator']) ? $options['separator'] : "\n";
$tag = isset($options['tag']) ? $options['tag'] : 'div'; $tag = isset($options['tag']) ? $options['tag'] : 'div';
unset($options['tag'], $options['unselect'], $options['encode'], $options['separator'], $options['item']); unset($options['tag'], $options['unselect'], $options['encode'], $options['separator'], $options['item'], $options['itemOptions']);
return $hidden . static::tag($tag, implode($separator, $lines), $options); return $hidden . static::tag($tag, implode($separator, $lines), $options);
} }
...@@ -805,6 +807,7 @@ class BaseHtml ...@@ -805,6 +807,7 @@ class BaseHtml
* - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. * - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true.
* This option is ignored if `item` option is set. * This option is ignored if `item` option is set.
* - separator: string, the HTML code that separates items. * - separator: string, the HTML code that separates items.
* - itemOptions: array, the options for generating the radio button tag using [[radio()]].
* - item: callable, a callback that can be used to customize the generation of the HTML code * - item: callable, a callback that can be used to customize the generation of the HTML code
* corresponding to a single item in $items. The signature of this callback must be: * corresponding to a single item in $items. The signature of this callback must be:
* *
...@@ -821,6 +824,7 @@ class BaseHtml ...@@ -821,6 +824,7 @@ class BaseHtml
{ {
$encode = !isset($options['encode']) || $options['encode']; $encode = !isset($options['encode']) || $options['encode'];
$formatter = isset($options['item']) ? $options['item'] : null; $formatter = isset($options['item']) ? $options['item'] : null;
$itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
$lines = []; $lines = [];
$index = 0; $index = 0;
foreach ($items as $value => $label) { foreach ($items as $value => $label) {
...@@ -830,10 +834,10 @@ class BaseHtml ...@@ -830,10 +834,10 @@ class BaseHtml
if ($formatter !== null) { if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value); $lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else { } else {
$lines[] = static::radio($name, $checked, [ $lines[] = static::radio($name, $checked, array_merge($itemOptions, [
'value' => $value, 'value' => $value,
'label' => $encode ? static::encode($label) : $label, 'label' => $encode ? static::encode($label) : $label,
]); ]));
} }
$index++; $index++;
} }
...@@ -847,7 +851,7 @@ class BaseHtml ...@@ -847,7 +851,7 @@ class BaseHtml
} }
$tag = isset($options['tag']) ? $options['tag'] : 'div'; $tag = isset($options['tag']) ? $options['tag'] : 'div';
unset($options['tag'], $options['unselect'], $options['encode'], $options['separator'], $options['item']); unset($options['tag'], $options['unselect'], $options['encode'], $options['separator'], $options['item'], $options['itemOptions']);
return $hidden . static::tag($tag, implode($separator, $lines), $options); return $hidden . static::tag($tag, implode($separator, $lines), $options);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment