Skip to content

Commit

Permalink
Merge branch 'kartik-v-patch-4'
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed May 21, 2014
2 parents 1803d66 + cb465bc commit b1b6a76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Yii Framework 2 Change Log
- Enh #3252: Added support for case insensitive matching using ILIKE to PostgreSQL QueryBuilder (cebe)
- Enh #3298: Supported configuring `View::theme` using a class name (netyum, qiangxue)
- Enh #3328: `BaseMailer` generates better text body from html body (armab)
- Enh #3518: `yii\helpers\Html::encode()` now replaces invalid code sequences with "�" (DaSourcerer)
- Enh #3472: Added configurable option to encode spaces in dropDownLists and listBoxes (kartik-v)
- Enh #3518: `yii\helpers\Html::encode()` now replaces invalid code sequences with "?" (DaSourcerer)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
Expand Down
4 changes: 4 additions & 0 deletions framework/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ Upgrade from Yii 2.0 Beta
* If you are sharing the same cache across different applications, you should configure
the `keyPrefix` property of the cache component to use some unique string.
Previously, this property was automatically assigned with a unique string.

* If you are using `dropDownList()`, `listBox()`, `activeDropDownList()`, or `activeListBox()`
of `yii\helpers\Html`, and your list options use multiple blank spaces to format and align
option label texts, you need to specify the option `encodeSpaces` to be true.
18 changes: 13 additions & 5 deletions framework/helpers/BaseHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ public static function checkbox($name, $checked = false, $options = [])
*
* - 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.
Expand All @@ -743,7 +745,6 @@ public static function dropDownList($name, $selection = null, $items = [], $opti
}
$options['name'] = $name;
$selectOptions = static::renderSelectOptions($selection, $items, $options);

return static::tag('select', "\n" . $selectOptions . "\n", $options);
}

Expand Down Expand Up @@ -777,6 +778,8 @@ public static function dropDownList($name, $selection = null, $items = [], $opti
* - 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.
Expand Down Expand Up @@ -804,7 +807,6 @@ public static function listBox($name, $selection = null, $items = [], $options =
$hidden = '';
}
$selectOptions = static::renderSelectOptions($selection, $items, $options);

return $hidden . static::tag('select', "\n" . $selectOptions . "\n", $options);
}

Expand Down Expand Up @@ -1354,6 +1356,8 @@ public static function activeCheckbox($model, $attribute, $options = [])
*
* - 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.
Expand Down Expand Up @@ -1407,6 +1411,8 @@ public static function activeDropDownList($model, $attribute, $items, $options =
* - 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.
Expand Down Expand Up @@ -1540,15 +1546,17 @@ public static function activeRadioList($model, $attribute, $items, $options = []
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] : [];
Expand All @@ -1562,7 +1570,7 @@ public static function renderSelectOptions($selection, $items, &$tagOptions = []
$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);
}
}

Expand Down

0 comments on commit b1b6a76

Please sign in to comment.