New attribute 'display_style' for Strings, Enums and ExternalKeys: when the list is short, display it as a set of radio buttons instead of a drop-down list. Possible values: 'radio', 'radio_vertical' and 'radio_horizontal'. ('radio' == 'radio_vertical').

SVN:trunk[1426]
This commit is contained in:
Denis Flaven
2011-08-06 09:51:06 +00:00
parent 61727aca02
commit 23b1d15b64
4 changed files with 138 additions and 47 deletions

View File

@@ -1520,24 +1520,39 @@ EOF
$iFieldSize = $oAttDef->GetMaxSize();
if ($aAllowedValues !== null)
{
// Discrete list of values, use a SELECT
$sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"$iId\">\n";
$sHTMLValue .= "<option value=\"\">".Dict::S('UI:SelectOne')."</option>\n";
foreach($aAllowedValues as $key => $display_value)
// Discrete list of values, use a SELECT or RADIO buttons depending on the config
$sDisplayStyle = $oAttDef->GetDisplayStyle();
switch($sDisplayStyle)
{
if ((count($aAllowedValues) == 1) && ($bMandatory == 'true') )
case 'radio':
case 'radio_horizontal':
case 'radio_vertical':
$sHTMLValue = '';
$bVertical = ($sDisplayStyle != 'radio_horizontal');
$sHTMLValue = $oPage->GetRadioButtons($aAllowedValues, $value, $iId, "{$sFieldPrefix}{$sAttCode}{$sNameSuffix}", $bMandatory, $bVertical, $sValidationField);
$aEventsList[] ='change';
break;
case 'select':
default:
$sHTMLValue = "<select title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" id=\"$iId\">\n";
$sHTMLValue .= "<option value=\"\">".Dict::S('UI:SelectOne')."</option>\n";
foreach($aAllowedValues as $key => $display_value)
{
// When there is only once choice, select it by default
$sSelected = ' selected';
if ((count($aAllowedValues) == 1) && ($bMandatory == 'true') )
{
// When there is only once choice, select it by default
$sSelected = ' selected';
}
else
{
$sSelected = ($value == $key) ? ' selected' : '';
}
$sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
}
else
{
$sSelected = ($value == $key) ? ' selected' : '';
}
$sHTMLValue .= "<option value=\"$key\"$sSelected>$display_value</option>\n";
$sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
$aEventsList[] ='change';
}
$sHTMLValue .= "</select>&nbsp;{$sValidationField}\n";
$aEventsList[] ='change';
}
else
{