Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
creocoder committed Oct 19, 2012
1 parent b94776c commit 8815f98
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions framework/web/helpers/CHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,16 @@ public static function checkBox($name,$checked=false,$htmlOptions=array())
public static function dropDownList($name,$select,$data,$htmlOptions=array())
{
$htmlOptions['name']=$name;

if(!isset($htmlOptions['id']))
$htmlOptions['id']=self::getIdByName($name);
elseif($htmlOptions['id']===false)
unset($htmlOptions['id']);

self::clientChange('change',$htmlOptions);
$options="\n".self::listOptions($select,$data,$htmlOptions);
$hidden='';

if(isset($htmlOptions['multiple']))
{
if(substr($htmlOptions['name'],-2)==='[]')
Expand All @@ -801,27 +805,20 @@ public static function dropDownList($name,$select,$data,$htmlOptions=array())

if(array_key_exists('unselectValue',$htmlOptions))
{
$unselect=$htmlOptions['unselectValue'];
unset($htmlOptions['unselectValue']);
}
else
$unselect=null;
if($htmlOptions['unselectValue']!==null)
{
// add a hidden field so that if the option is not selected, it still submits a value
if(isset($htmlOptions['id']) && $htmlOptions['id']!==false)
$unselectOptions=array('id'=>self::ID_PREFIX.$htmlOptions['id']);
else
$unselectOptions=array('id'=>false);

if($unselect!==null)
{
// add a hidden field so that if the option is not selected, it still submits a value
if(isset($htmlOptions['id']) && $htmlOptions['id']!==false)
$unselectOptions=array('id'=>self::ID_PREFIX.$htmlOptions['id']);
else
$unselectOptions=array('id'=>false);
$hidden=self::hiddenField($hiddenName,$unselect,$unselectOptions);
$hidden=self::hiddenField($hiddenName,$htmlOptions['unselectValue'],$unselectOptions);
}

unset($htmlOptions['unselectValue']);
}
else
$hidden='';
}
else
$hidden='';

// add a hidden field so that if the option is not selected, it still submits a value
return $hidden . self::tag('select',$htmlOptions,$options);
}
Expand Down Expand Up @@ -1580,8 +1577,12 @@ public static function activeDropDownList($model,$attribute,$data,$htmlOptions=a
$selection=self::resolveValue($model,$attribute);
$options="\n".self::listOptions($selection,$data,$htmlOptions);
self::clientChange('change',$htmlOptions);

if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);

$hidden='';

if(isset($htmlOptions['multiple']))
{
if(substr($htmlOptions['name'],-2)==='[]')
Expand All @@ -1592,19 +1593,17 @@ public static function activeDropDownList($model,$attribute,$data,$htmlOptions=a
$htmlOptions['name'].='[]';
}

if(array_key_exists('unselectValue',$htmlOptions))
if(!array_key_exists('unselectValue',$htmlOptions))
$htmlOptions['unselectValue']='';

if($htmlOptions['unselectValue']!==null)
{
$unselect=$htmlOptions['unselectValue'];
unset($htmlOptions['unselectValue']);
$hiddenOptions=isset($htmlOptions['id']) ? array('id'=>self::ID_PREFIX.$htmlOptions['id']) : array('id'=>false);
$hidden=self::hiddenField($hiddenName,$htmlOptions['unselectValue'],$hiddenOptions);
}
else
$unselect='';

$hiddenOptions=isset($htmlOptions['id']) ? array('id'=>self::ID_PREFIX.$htmlOptions['id']) : array('id'=>false);
$hidden=$unselect!==null ? self::hiddenField($hiddenName,$unselect,$hiddenOptions) : '';
unset($htmlOptions['unselectValue']);
}
else
$hidden='';

return $hidden . self::tag('select',$htmlOptions,$options);
}
Expand Down

0 comments on commit 8815f98

Please sign in to comment.