|
|
|
@ -819,6 +819,8 @@ class BaseHtml
|
|
|
|
|
* Defaults to false. |
|
|
|
|
* - encode: bool, whether to encode option prompt and option value characters. |
|
|
|
|
* Defaults to `true`. This option is available since 2.0.3. |
|
|
|
|
* - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. |
|
|
|
|
* This option is available since 2.0.37. |
|
|
|
|
* |
|
|
|
|
* The rest of the options will be rendered as the attributes of the resulting tag. The values will |
|
|
|
|
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. |
|
|
|
@ -877,6 +879,8 @@ class BaseHtml
|
|
|
|
|
* Defaults to false. |
|
|
|
|
* - encode: bool, whether to encode option prompt and option value characters. |
|
|
|
|
* Defaults to `true`. This option is available since 2.0.3. |
|
|
|
|
* - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. |
|
|
|
|
* This option is available since 2.0.37. |
|
|
|
|
* |
|
|
|
|
* The rest of the options will be rendered as the attributes of the resulting tag. The values will |
|
|
|
|
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. |
|
|
|
@ -931,6 +935,8 @@ class BaseHtml
|
|
|
|
|
* This option is available since version 2.0.16. |
|
|
|
|
* - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. |
|
|
|
|
* This option is ignored if `item` option is set. |
|
|
|
|
* - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. |
|
|
|
|
* This option is available since 2.0.37. |
|
|
|
|
* - separator: string, the HTML code that separates items. |
|
|
|
|
* - itemOptions: array, the options for generating the checkbox tag using [[checkbox()]]. |
|
|
|
|
* - item: callable, a callback that can be used to customize the generation of the HTML code |
|
|
|
@ -962,13 +968,14 @@ class BaseHtml
|
|
|
|
|
$encode = ArrayHelper::remove($options, 'encode', true); |
|
|
|
|
$separator = ArrayHelper::remove($options, 'separator', "\n"); |
|
|
|
|
$tag = ArrayHelper::remove($options, 'tag', 'div'); |
|
|
|
|
$strict = ArrayHelper::remove($options, 'strict', false); |
|
|
|
|
|
|
|
|
|
$lines = []; |
|
|
|
|
$index = 0; |
|
|
|
|
foreach ($items as $value => $label) { |
|
|
|
|
$checked = $selection !== null && |
|
|
|
|
(!ArrayHelper::isTraversable($selection) && !strcmp($value, $selection) |
|
|
|
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection)); |
|
|
|
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection, $strict)); |
|
|
|
|
if ($formatter !== null) { |
|
|
|
|
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value); |
|
|
|
|
} else { |
|
|
|
@ -1021,6 +1028,8 @@ class BaseHtml
|
|
|
|
|
* This option is available since version 2.0.16. |
|
|
|
|
* - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. |
|
|
|
|
* This option is ignored if `item` option is set. |
|
|
|
|
* - strict: boolean, if `$selection` is an array and this value is true a strict comparison will be performed on `$items` keys. Defaults to false. |
|
|
|
|
* This option is available since 2.0.37. |
|
|
|
|
* - 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 |
|
|
|
@ -1049,6 +1058,7 @@ class BaseHtml
|
|
|
|
|
$encode = ArrayHelper::remove($options, 'encode', true); |
|
|
|
|
$separator = ArrayHelper::remove($options, 'separator', "\n"); |
|
|
|
|
$tag = ArrayHelper::remove($options, 'tag', 'div'); |
|
|
|
|
$strict = ArrayHelper::remove($options, 'strict', false); |
|
|
|
|
|
|
|
|
|
$hidden = ''; |
|
|
|
|
if (isset($options['unselect'])) { |
|
|
|
@ -1067,7 +1077,7 @@ class BaseHtml
|
|
|
|
|
foreach ($items as $value => $label) { |
|
|
|
|
$checked = $selection !== null && |
|
|
|
|
(!ArrayHelper::isTraversable($selection) && !strcmp($value, $selection) |
|
|
|
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection)); |
|
|
|
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection, $strict)); |
|
|
|
|
if ($formatter !== null) { |
|
|
|
|
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value); |
|
|
|
|
} else { |
|
|
|
@ -1860,6 +1870,7 @@ class BaseHtml
|
|
|
|
|
$lines = []; |
|
|
|
|
$encodeSpaces = ArrayHelper::remove($tagOptions, 'encodeSpaces', false); |
|
|
|
|
$encode = ArrayHelper::remove($tagOptions, 'encode', true); |
|
|
|
|
$strict = ArrayHelper::remove($tagOptions, 'strict', false); |
|
|
|
|
if (isset($tagOptions['prompt'])) { |
|
|
|
|
$promptOptions = ['value' => '']; |
|
|
|
|
if (is_string($tagOptions['prompt'])) { |
|
|
|
@ -1887,7 +1898,7 @@ class BaseHtml
|
|
|
|
|
if (!isset($groupAttrs['label'])) { |
|
|
|
|
$groupAttrs['label'] = $key; |
|
|
|
|
} |
|
|
|
|
$attrs = ['options' => $options, 'groups' => $groups, 'encodeSpaces' => $encodeSpaces, 'encode' => $encode]; |
|
|
|
|
$attrs = ['options' => $options, 'groups' => $groups, 'encodeSpaces' => $encodeSpaces, 'encode' => $encode, 'strict' => $strict]; |
|
|
|
|
$content = static::renderSelectOptions($selection, $value, $attrs); |
|
|
|
|
$lines[] = static::tag('optgroup', "\n" . $content . "\n", $groupAttrs); |
|
|
|
|
} else { |
|
|
|
@ -1896,7 +1907,7 @@ class BaseHtml
|
|
|
|
|
if (!array_key_exists('selected', $attrs)) { |
|
|
|
|
$attrs['selected'] = $selection !== null && |
|
|
|
|
(!ArrayHelper::isTraversable($selection) && !strcmp($key, $selection) |
|
|
|
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$key, $selection)); |
|
|
|
|
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$key, $selection, $strict)); |
|
|
|
|
} |
|
|
|
|
$text = $encode ? static::encode($value) : $value; |
|
|
|
|
if ($encodeSpaces) { |
|
|
|
|