Skip to content

Commit b3c7a9d

Browse files
dariusstefanrazvancrainea
authored andcommitted
alias_mgm: auto-complete field in select form, when only one or zero values are available
1 parent dc8e626 commit b3c7a9d

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

Diff for: web/common/forms.php

+40-16
Original file line numberDiff line numberDiff line change
@@ -459,25 +459,49 @@ function form_generate_select($title,$tip,$id,$mlen,$val,$vals,$texts=null,$is_o
459459
if (!is_null($tip))
460460
print(" <div class='tooltip'><sup>?</sup>
461461
<span class='tooltiptext'>".$tip."</span>
462-
</div> ");
462+
</div>");
463463
print("
464464
</td>
465465
<td class='dataRecord' width='250'>
466-
<table style='width:100%'><tr><td>
467-
<select name='".$id."' id='".$id."' style='width: ".$mlen."px;' class='dataSelect'>");
468-
if ($is_optional) {
469-
print(" <option value=''".(($val=="")?" selected":"").">Empty ...</option>");
470-
}
471-
for($i = 0; $i < count($vals); ++$i){
472-
print("
473-
<option value='".$vals[$i]."'".(($val==$vals[$i])?" selected":"").">".($texts[$i]?$texts[$i]:$vals[$i])."</option>");
474-
}
475-
print("
476-
</select>
477-
</td>
478-
<td width='20'>
479-
<div id='".$id."_ok'></div>
480-
</td></tr></table>
466+
<table style='width:100%'>
467+
<tr>
468+
<td>");
469+
470+
$options_count = count($vals);
471+
if ($options_count == 1 && !$is_optional) {
472+
print(" <input type='text' name='".$id."' value='".$vals[0]."' readonly style='width: 205px' class='dataSelect'>");
473+
} else {
474+
if ($options_count == 0) {
475+
$text = $is_optional ? "Empty ..." : "No options available";
476+
477+
if (!$is_optional) {
478+
print(" <select name='".$id."' id='".$id."' style='width: ".$mlen."px;' class='dataSelect' disabled>");
479+
print(" <option value=''>".$text."</option>");
480+
print(" </select>");
481+
} else {
482+
print(" <input type='text' name='".$id."' value='' readonly style='width: 205px' class='dataSelect' placeholder='".$text."'>");
483+
}
484+
} else {
485+
print(" <select name='".$id."' id='".$id."' style='width: ".$mlen."px;' class='dataSelect'>");
486+
487+
if ($is_optional) {
488+
print(" <option value=''".(($val=="")?" selected":"").">Empty ...</option>");
489+
}
490+
491+
for($i = 0; $i < count($vals); ++$i){
492+
print(" <option value='".$vals[$i]."'".(($val==$vals[$i])?" selected":"").">".($texts[$i]?$texts[$i]:$vals[$i])."</option>");
493+
}
494+
495+
print(" </select>");
496+
}
497+
}
498+
499+
print(" </td>
500+
<td width='20'>
501+
<div id='".$id."_ok'></div>
502+
</td>
503+
</tr>
504+
</table>
481505
</td>
482506
</tr>");
483507
}

Diff for: web/tools/users/alias_management/lib/functions.inc.php

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ function print_domains($type,$value,$has_any)
4949
$temp ='';
5050
$end_index = sizeof($options);
5151

52+
if ($end_index == 0)
53+
return;
54+
55+
if ($end_index == 1) {
56+
echo('<input type="text" name="'.$type.'" value="'.$options[0][value].'" readonly style="width: 205px" class="dataSelect">');
57+
return;
58+
}
59+
5260
echo('<select ');
5361
if (isset($_SESSION['fromusrmgmt']) && ($_SESSION['fromusrmgmt'])) echo "disabled ";
5462
echo('name='.$type.' id='.$type.' size="1" style="width: 205px" class="dataSelect">');
@@ -78,6 +86,14 @@ function print_aliasType($value, $has_any)
7886
}
7987
$start_index = 0;
8088
$end_index = sizeof($options);
89+
90+
if ($end_index == 0)
91+
return;
92+
93+
if ($end_index == 1) {
94+
echo('<input type="text" name="'.$type.'" value="'.$options[0][label].'" readonly style="width: 205px" class="dataSelect">');
95+
return;
96+
}
8197
?>
8298
<select name="alias_type" id="alias_type" size="1" style="width: 190px" class="dataSelect">
8399
<?php

Diff for: web/tools/users/user_management/lib/functions.inc.php

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function print_aliasType($value)
3636
$options = get_alias_types();
3737
$start_index = 0;
3838
$end_index = sizeof($options);
39+
40+
if ($end_index == 0)
41+
return;
42+
43+
if ($end_index == 1) {
44+
echo('<input type="text" name="'.$type.'" value="'.$options[0][label].'" readonly style="width: 205px" class="dataSelect">');
45+
return;
46+
}
3947
?>
4048
<select name="alias_type" id="alias_type" size="1" style="width: 205px" class="dataSelect">
4149
<?php
@@ -67,6 +75,14 @@ function print_domains($type,$value,$has_any)
6775
$temp = '';
6876
$end_index = sizeof($domains);
6977

78+
if ($end_index == 0)
79+
return;
80+
81+
if ($end_index == 1) {
82+
echo('<input type="text" name="'.$type.'" value="'.$domains[0].'" readonly style="width: 205px" class="dataSelect">');
83+
return;
84+
}
85+
7086
echo('<select name='.$type.' id='.$type.' size="1" style="width: 205px" class="dataSelect">');
7187
if ($value!=NULL && $value!="") {
7288
echo('<option value="'.$value. '" selected > '.$value.'</option>');

0 commit comments

Comments
 (0)