Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
0ed190e9
Commit
0ed190e9
authored
May 19, 2014
by
Kartik Visweswaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #3472: Configurable option to encode spaces in dropdowns
parent
5439ab78
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
BaseHtml.php
framework/helpers/BaseHtml.php
+14
-6
No files found.
framework/helpers/BaseHtml.php
View file @
0ed190e9
...
@@ -729,6 +729,8 @@ class BaseHtml
...
@@ -729,6 +729,8 @@ class BaseHtml
*
*
* - groups: array, the attributes for the optgroup tags. The structure of this is similar to that of '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.
* 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 `true`.
*
*
* The rest of the options will be rendered as the attributes of the resulting tag. The values will
* 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.
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
...
@@ -742,7 +744,8 @@ class BaseHtml
...
@@ -742,7 +744,8 @@ class BaseHtml
return
static
::
listBox
(
$name
,
$selection
,
$items
,
$options
);
return
static
::
listBox
(
$name
,
$selection
,
$items
,
$options
);
}
}
$options
[
'name'
]
=
$name
;
$options
[
'name'
]
=
$name
;
$selectOptions
=
static
::
renderSelectOptions
(
$selection
,
$items
,
$options
);
$encodeSpaces
=
ArrayHelper
::
remove
(
$options
,
'encodeSpaces'
,
true
);
$selectOptions
=
static
::
renderSelectOptions
(
$selection
,
$items
,
$options
,
$encodeSpaces
);
return
static
::
tag
(
'select'
,
"
\n
"
.
$selectOptions
.
"
\n
"
,
$options
);
return
static
::
tag
(
'select'
,
"
\n
"
.
$selectOptions
.
"
\n
"
,
$options
);
}
}
...
@@ -777,6 +780,8 @@ class BaseHtml
...
@@ -777,6 +780,8 @@ class BaseHtml
* - unselect: string, the value that will be submitted when no option is selected.
* - 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
* 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.
* 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 `true`.
*
*
* The rest of the options will be rendered as the attributes of the resulting tag. The values will
* 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.
* be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
...
@@ -803,7 +808,8 @@ class BaseHtml
...
@@ -803,7 +808,8 @@ class BaseHtml
}
else
{
}
else
{
$hidden
=
''
;
$hidden
=
''
;
}
}
$selectOptions
=
static
::
renderSelectOptions
(
$selection
,
$items
,
$options
);
$encodeSpaces
=
ArrayHelper
::
remove
(
$options
,
'encodeSpaces'
,
true
);
$selectOptions
=
static
::
renderSelectOptions
(
$selection
,
$items
,
$options
,
$encodeSpaces
);
return
$hidden
.
static
::
tag
(
'select'
,
"
\n
"
.
$selectOptions
.
"
\n
"
,
$options
);
return
$hidden
.
static
::
tag
(
'select'
,
"
\n
"
.
$selectOptions
.
"
\n
"
,
$options
);
}
}
...
@@ -1534,14 +1540,16 @@ class BaseHtml
...
@@ -1534,14 +1540,16 @@ class BaseHtml
* @param array $tagOptions the $options parameter that is passed to the [[dropDownList()]] or [[listBox()]] call.
* @param array $tagOptions the $options parameter that is passed to the [[dropDownList()]] or [[listBox()]] call.
* This method will take out these elements, if any: "prompt", "options" and "groups". See more details
* This method will take out these elements, if any: "prompt", "options" and "groups". See more details
* in [[dropDownList()]] for the explanation of these elements.
* in [[dropDownList()]] for the explanation of these elements.
* @param bool $encodeSpaces whether to encode spaces in option prompt and option value with ` ` character.
* Defaults to `true`.
*
*
* @return string the generated list options
* @return string the generated list options
*/
*/
public
static
function
renderSelectOptions
(
$selection
,
$items
,
&
$tagOptions
=
[])
public
static
function
renderSelectOptions
(
$selection
,
$items
,
&
$tagOptions
=
[]
,
$encodeSpaces
=
true
)
{
{
$lines
=
[];
$lines
=
[];
if
(
isset
(
$tagOptions
[
'prompt'
]))
{
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'
=>
''
]);
$lines
[]
=
static
::
tag
(
'option'
,
$prompt
,
[
'value'
=>
''
]);
}
}
...
@@ -1554,7 +1562,7 @@ class BaseHtml
...
@@ -1554,7 +1562,7 @@ class BaseHtml
$groupAttrs
=
isset
(
$groups
[
$key
])
?
$groups
[
$key
]
:
[];
$groupAttrs
=
isset
(
$groups
[
$key
])
?
$groups
[
$key
]
:
[];
$groupAttrs
[
'label'
]
=
$key
;
$groupAttrs
[
'label'
]
=
$key
;
$attrs
=
[
'options'
=>
$options
,
'groups'
=>
$groups
];
$attrs
=
[
'options'
=>
$options
,
'groups'
=>
$groups
];
$content
=
static
::
renderSelectOptions
(
$selection
,
$value
,
$attrs
);
$content
=
static
::
renderSelectOptions
(
$selection
,
$value
,
$attrs
,
$encodeSpaces
);
$lines
[]
=
static
::
tag
(
'optgroup'
,
"
\n
"
.
$content
.
"
\n
"
,
$groupAttrs
);
$lines
[]
=
static
::
tag
(
'optgroup'
,
"
\n
"
.
$content
.
"
\n
"
,
$groupAttrs
);
}
else
{
}
else
{
$attrs
=
isset
(
$options
[
$key
])
?
$options
[
$key
]
:
[];
$attrs
=
isset
(
$options
[
$key
])
?
$options
[
$key
]
:
[];
...
@@ -1562,7 +1570,7 @@ class BaseHtml
...
@@ -1562,7 +1570,7 @@ class BaseHtml
$attrs
[
'selected'
]
=
$selection
!==
null
&&
$attrs
[
'selected'
]
=
$selection
!==
null
&&
(
!
is_array
(
$selection
)
&&
!
strcmp
(
$key
,
$selection
)
(
!
is_array
(
$selection
)
&&
!
strcmp
(
$key
,
$selection
)
||
is_array
(
$selection
)
&&
in_array
(
$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
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment