mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Merge branch 'patch-4' of github.com:kartik-v/yii2 into kartik-v-patch-4
Conflicts: framework/CHANGELOG.md
This commit is contained in:
@ -729,6 +729,8 @@ class BaseHtml
|
||||
*
|
||||
* - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options',
|
||||
* except that the array keys represent the optgroup labels specified in $items.
|
||||
* - encodeSpaces: bool, whether to encode spaces in option prompt and option value with ` ` character.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* 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.
|
||||
@ -743,7 +745,6 @@ class BaseHtml
|
||||
}
|
||||
$options['name'] = $name;
|
||||
$selectOptions = static::renderSelectOptions($selection, $items, $options);
|
||||
|
||||
return static::tag('select', "\n" . $selectOptions . "\n", $options);
|
||||
}
|
||||
|
||||
@ -777,6 +778,8 @@ class BaseHtml
|
||||
* - unselect: string, the value that will be submitted when no option is selected.
|
||||
* When this attribute is set, a hidden field will be generated so that if no option is selected in multiple
|
||||
* mode, we can still obtain the posted unselect value.
|
||||
* - encodeSpaces: bool, whether to encode spaces in option prompt and option value with ` ` character.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* 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.
|
||||
@ -804,7 +807,6 @@ class BaseHtml
|
||||
$hidden = '';
|
||||
}
|
||||
$selectOptions = static::renderSelectOptions($selection, $items, $options);
|
||||
|
||||
return $hidden . static::tag('select', "\n" . $selectOptions . "\n", $options);
|
||||
}
|
||||
|
||||
@ -1354,6 +1356,8 @@ class BaseHtml
|
||||
*
|
||||
* - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of 'options',
|
||||
* except that the array keys represent the optgroup labels specified in $items.
|
||||
* - encodeSpaces: bool, whether to encode spaces in option prompt and option value with ` ` character.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* 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.
|
||||
@ -1407,6 +1411,8 @@ class BaseHtml
|
||||
* - unselect: string, the value that will be submitted when no option is selected.
|
||||
* When this attribute is set, a hidden field will be generated so that if no option is selected in multiple
|
||||
* mode, we can still obtain the posted unselect value.
|
||||
* - encodeSpaces: bool, whether to encode spaces in option prompt and option value with ` ` character.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* 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.
|
||||
@ -1540,15 +1546,17 @@ class BaseHtml
|
||||
public static function renderSelectOptions($selection, $items, &$tagOptions = [])
|
||||
{
|
||||
$lines = [];
|
||||
$encodeSpaces = ArrayHelper::remove($tagOptions, 'encodeSpaces', false);
|
||||
if (isset($tagOptions['prompt'])) {
|
||||
$prompt = str_replace(' ', ' ', static::encode($tagOptions['prompt']));
|
||||
$prompt = $encodeSpaces ? str_replace(' ', ' ', static::encode($tagOptions['prompt'])) : static::encode($tagOptions['prompt']);
|
||||
$lines[] = static::tag('option', $prompt, ['value' => '']);
|
||||
}
|
||||
|
||||
$options = isset($tagOptions['options']) ? $tagOptions['options'] : [];
|
||||
$groups = isset($tagOptions['groups']) ? $tagOptions['groups'] : [];
|
||||
unset($tagOptions['prompt'], $tagOptions['options'], $tagOptions['groups']);
|
||||
|
||||
$options['encodeSpaces'] = ArrayHelper::getValue($options, 'encodeSpaces', $encodeSpaces);
|
||||
|
||||
foreach ($items as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$groupAttrs = isset($groups[$key]) ? $groups[$key] : [];
|
||||
@ -1562,7 +1570,7 @@ class BaseHtml
|
||||
$attrs['selected'] = $selection !== null &&
|
||||
(!is_array($selection) && !strcmp($key, $selection)
|
||||
|| is_array($selection) && in_array($key, $selection));
|
||||
$lines[] = static::tag('option', str_replace(' ', ' ', static::encode($value)), $attrs);
|
||||
$lines[] = static::tag('option', ($encodeSpaces ? str_replace(' ', ' ', static::encode($value)) : static::encode($value)), $attrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user