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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
a4b7d493
Commit
a4b7d493
authored
Apr 27, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed the $value parameter from radio and checkbox.
parent
ee777e84
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
23 deletions
+19
-23
Html.php
framework/helpers/base/Html.php
+13
-17
HtmlTest.php
tests/unit/framework/helpers/HtmlTest.php
+6
-6
No files found.
framework/helpers/base/Html.php
View file @
a4b7d493
...
...
@@ -609,7 +609,6 @@ class Html
* Generates a radio button input.
* @param string $name the name attribute.
* @param boolean $checked whether the radio button should be checked.
* @param string $value the value attribute. If it is null, the value attribute will not be rendered.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
*
* - uncheck: string, the value associated with the uncheck state of the radio button. When this attribute
...
...
@@ -621,10 +620,10 @@ class Html
*
* @return string the generated radio button tag
*/
public
static
function
radio
(
$name
,
$checked
=
false
,
$
value
=
'1'
,
$
options
=
array
())
public
static
function
radio
(
$name
,
$checked
=
false
,
$options
=
array
())
{
$options
[
'checked'
]
=
$checked
;
$
options
[
'value'
]
=
$value
;
$
value
=
array_key_exists
(
'value'
,
$options
)
?
$options
[
'value'
]
:
'1'
;
if
(
isset
(
$options
[
'uncheck'
]))
{
// add a hidden field so that if the radio button is not selected, it still submits a value
$hidden
=
static
::
hiddenInput
(
$name
,
$options
[
'uncheck'
]);
...
...
@@ -639,7 +638,6 @@ class Html
* Generates a checkbox input.
* @param string $name the name attribute.
* @param boolean $checked whether the checkbox should be checked.
* @param string $value the value attribute. If it is null, the value attribute will not be rendered.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
*
* - uncheck: string, the value associated with the uncheck state of the checkbox. When this attribute
...
...
@@ -651,10 +649,10 @@ class Html
*
* @return string the generated checkbox tag
*/
public
static
function
checkbox
(
$name
,
$checked
=
false
,
$
value
=
'1'
,
$
options
=
array
())
public
static
function
checkbox
(
$name
,
$checked
=
false
,
$options
=
array
())
{
$options
[
'checked'
]
=
$checked
;
$
options
[
'value'
]
=
$value
;
$
value
=
array_key_exists
(
'value'
,
$options
)
?
$options
[
'value'
]
:
'1'
;
if
(
isset
(
$options
[
'uncheck'
]))
{
// add a hidden field so that if the checkbox is not selected, it still submits a value
$hidden
=
static
::
hiddenInput
(
$name
,
$options
[
'uncheck'
]);
...
...
@@ -806,7 +804,7 @@ class Html
if
(
$formatter
!==
null
)
{
$lines
[]
=
call_user_func
(
$formatter
,
$index
,
$label
,
$name
,
$checked
,
$value
);
}
else
{
$lines
[]
=
static
::
label
(
static
::
checkbox
(
$name
,
$checked
,
$value
)
.
' '
.
$label
);
$lines
[]
=
static
::
label
(
static
::
checkbox
(
$name
,
$checked
,
array
(
'value'
=>
$value
)
)
.
' '
.
$label
);
}
$index
++
;
}
...
...
@@ -860,7 +858,7 @@ class Html
if
(
$formatter
!==
null
)
{
$lines
[]
=
call_user_func
(
$formatter
,
$index
,
$label
,
$name
,
$checked
,
$value
);
}
else
{
$lines
[]
=
static
::
label
(
static
::
radio
(
$name
,
$checked
,
$value
)
.
' '
.
$label
);
$lines
[]
=
static
::
label
(
static
::
radio
(
$name
,
$checked
,
array
(
'value'
=>
$value
)
)
.
' '
.
$label
);
}
$index
++
;
}
...
...
@@ -1013,7 +1011,6 @@ class Html
* @param Model $model the model object
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param string $value the value tag attribute. If it is null, the value attribute will not be rendered.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
*
* - uncheck: string, the value associated with the uncheck state of the radio button. If not set,
...
...
@@ -1026,17 +1023,17 @@ class Html
*
* @return string the generated radio button tag
*/
public
static
function
activeRadio
(
$model
,
$attribute
,
$
value
=
'1'
,
$
options
=
array
())
public
static
function
activeRadio
(
$model
,
$attribute
,
$options
=
array
())
{
$name
=
isset
(
$options
[
'name'
])
?
$options
[
'name'
]
:
static
::
getInputName
(
$model
,
$attribute
);
$checked
=
static
::
getAttributeValue
(
$model
,
$attribute
);
if
(
!
array_key_exists
(
'uncheck'
,
$options
))
{
$options
[
'uncheck
ed
'
]
=
'0'
;
$options
[
'uncheck'
]
=
'0'
;
}
if
(
!
array_key_exists
(
'id'
,
$options
))
{
$options
[
'id'
]
=
static
::
getInputId
(
$model
,
$attribute
);
}
return
static
::
radio
(
$name
,
$checked
,
$
value
,
$
options
);
return
static
::
radio
(
$name
,
$checked
,
$options
);
}
/**
...
...
@@ -1046,7 +1043,6 @@ class Html
* @param Model $model the model object
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param string $value the value tag attribute. If it is null, the value attribute will not be rendered.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
*
* - uncheck: string, the value associated with the uncheck state of the radio button. If not set,
...
...
@@ -1059,17 +1055,17 @@ class Html
*
* @return string the generated checkbox tag
*/
public
static
function
activeCheckbox
(
$model
,
$attribute
,
$
value
=
'1'
,
$
options
=
array
())
public
static
function
activeCheckbox
(
$model
,
$attribute
,
$options
=
array
())
{
$name
=
isset
(
$options
[
'name'
])
?
$options
[
'name'
]
:
static
::
getInputName
(
$model
,
$attribute
);
$checked
=
static
::
getAttributeValue
(
$model
,
$attribute
);
if
(
!
array_key_exists
(
'uncheck'
,
$options
))
{
$options
[
'uncheck
ed
'
]
=
'0'
;
$options
[
'uncheck'
]
=
'0'
;
}
if
(
!
array_key_exists
(
'id'
,
$options
))
{
$options
[
'id'
]
=
static
::
getInputId
(
$model
,
$attribute
);
}
return
static
::
checkbox
(
$name
,
$checked
,
$
value
,
$
options
);
return
static
::
checkbox
(
$name
,
$checked
,
$options
);
}
/**
...
...
@@ -1468,7 +1464,7 @@ class Html
*/
public
static
function
getInputId
(
$model
,
$attribute
)
{
$name
=
st
atic
::
getInputName
(
$model
,
$attribute
);
$name
=
st
rtolower
(
static
::
getInputName
(
$model
,
$attribute
)
);
return
str_replace
(
array
(
'[]'
,
']['
,
'['
,
']'
,
' '
),
array
(
''
,
'-'
,
'-'
,
''
,
'-'
),
$name
);
}
...
...
tests/unit/framework/helpers/HtmlTest.php
View file @
a4b7d493
...
...
@@ -230,15 +230,15 @@ class HtmlTest extends \yii\test\TestCase
public
function
testRadio
()
{
$this
->
assertEquals
(
'<input type="radio" name="test" value="1" />'
,
Html
::
radio
(
'test'
));
$this
->
assertEquals
(
'<input type="radio" class="a" name="test" checked="checked" />'
,
Html
::
radio
(
'test'
,
true
,
null
,
array
(
'class'
=>
'a'
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0" /><input type="radio" class="a" name="test" value="2" checked="checked" />'
,
Html
::
radio
(
'test'
,
true
,
2
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
)));
$this
->
assertEquals
(
'<input type="radio" class="a" name="test" checked="checked" />'
,
Html
::
radio
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'value'
=>
null
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0" /><input type="radio" class="a" name="test" value="2" checked="checked" />'
,
Html
::
radio
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
,
'value'
=>
2
)));
}
public
function
testCheckbox
()
{
$this
->
assertEquals
(
'<input type="checkbox" name="test" value="1" />'
,
Html
::
checkbox
(
'test'
));
$this
->
assertEquals
(
'<input type="checkbox" class="a" name="test" checked="checked" />'
,
Html
::
checkbox
(
'test'
,
true
,
null
,
array
(
'class'
=>
'a'
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0" /><input type="checkbox" class="a" name="test" value="2" checked="checked" />'
,
Html
::
checkbox
(
'test'
,
true
,
2
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
)));
$this
->
assertEquals
(
'<input type="checkbox" class="a" name="test" checked="checked" />'
,
Html
::
checkbox
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'value'
=>
null
)));
$this
->
assertEquals
(
'<input type="hidden" name="test" value="0" /><input type="checkbox" class="a" name="test" value="2" checked="checked" />'
,
Html
::
checkbox
(
'test'
,
true
,
array
(
'class'
=>
'a'
,
'uncheck'
=>
'0'
,
'value'
=>
2
)));
}
public
function
testDropDownList
()
...
...
@@ -347,7 +347,7 @@ EOD;
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
checkboxList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems
(),
array
(
'item'
=>
function
(
$index
,
$label
,
$name
,
$checked
,
$value
)
{
return
$index
.
Html
::
label
(
$label
.
' '
.
Html
::
checkbox
(
$name
,
$checked
,
$value
));
return
$index
.
Html
::
label
(
$label
.
' '
.
Html
::
checkbox
(
$name
,
$checked
,
array
(
'value'
=>
$value
)
));
}
)));
}
...
...
@@ -383,7 +383,7 @@ EOD;
EOD;
$this
->
assertEqualsWithoutLE
(
$expected
,
Html
::
radioList
(
'test'
,
array
(
'value2'
),
$this
->
getDataItems
(),
array
(
'item'
=>
function
(
$index
,
$label
,
$name
,
$checked
,
$value
)
{
return
$index
.
Html
::
label
(
$label
.
' '
.
Html
::
radio
(
$name
,
$checked
,
$value
));
return
$index
.
Html
::
label
(
$label
.
' '
.
Html
::
radio
(
$name
,
$checked
,
array
(
'value'
=>
$value
)
));
}
)));
}
...
...
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