Open StefanAbel-OTOBO opened 3 months ago
I managed to track the root bug down. There are a number of things which come into play to create the environment, but in the end it boils down to:
Double quote precedes minus precedes alphanumeric character
in regard to perl sort. Please feel free to ask me for further details, but I didn't want to clutter this comment.
I see two possible ways to solve the root cause:
"" => '-'
within selection datasub BuildSelection {
[...]
if ( !defined $Param{SelectedID} && !defined $Param{SelectedValue} ) {
$Param{SelectedID} = '';
}
[...]
}
For the interested reader, the place where the mentioned sorting takes place is here:
Is reproducible with a standard dropdown dynamic field including "-"
as value. (Probably just "
suffices.)
See probably: https://github.com/RotherOSS/otobo/blob/fecfc99615e486d34aa887cd180c7b4317a2e175/var/httpd/htdocs/js/Core.UI.InputFields.js#L568 which, if no option is selected returns the first option, and line 594 where an empty key is skipped. Problem arises when stuff ("
) is sorted in front of the empty value (-
). (See also backend sorting above.)
DF dropdown has empty value pre-selected
DF dropdown has one of the weird values from above pre-selected , eg '"-"'
Combination of the backend sorting and the way the frontend handles selection (see above comments)
diff --git a/Kernel/Output/HTML/Layout.pm b/Kernel/Output/HTML/Layout.pm
index 86b163855..ae3a6ba35 100644
--- a/Kernel/Output/HTML/Layout.pm
+++ b/Kernel/Output/HTML/Layout.pm
@@ -5919,6 +5919,9 @@ sub _BuildSelectionDataRefCreate {
}
else {
@SortKeys = sort {
+ # assure the empty option, if any, is always sorted first
+ if($a eq '' ) { return -1; }
+ if($b eq '' ) { return 1; }
lc( $DataLocal->{$a} // '' )
cmp lc( $DataLocal->{$b} // '' )
} ( keys %{$DataLocal} );
That seems to work but adds 2 condition checks in the inner sort loop., albeit cheap ones.
Alternative is less condition checks but more typing:
diff --git a/Kernel/Output/HTML/Layout.pm b/Kernel/Output/HTML/Layout.pm
index 86b163855..fa7d013cd 100644
--- a/Kernel/Output/HTML/Layout.pm
+++ b/Kernel/Output/HTML/Layout.pm
@@ -5918,10 +5918,15 @@ sub _BuildSelectionDataRefCreate {
# already done before the translation
}
else {
+ my $EmptyValue = delete $DataLocal->{''};
@SortKeys = sort {
lc( $DataLocal->{$a} // '' )
cmp lc( $DataLocal->{$b} // '' )
} ( keys %{$DataLocal} );
+ if( defined $EmptyValue) {
+ $DataLocal->{''} = $EmptyValue;
+ unshift @SortKeys, '';
+ }
$OptionRef->{Sort} = 'AlphanumericValue';
}
diff --git a/var/httpd/htdocs/js/Core.UI.InputFields.js b/var/httpd/htdocs/js/Core.UI.InputFields.js
index 431745e85..7273b591e 100644
--- a/var/httpd/htdocs/js/Core.UI.InputFields.js
+++ b/var/httpd/htdocs/js/Core.UI.InputFields.js
@@ -565,7 +565,7 @@ Core.UI.InputFields = (function (TargetNS) {
Selection = $.unique($SelectObj.val());
SelectionLength = Selection.length;
} else {
- Selection = [ $SelectObj.val() ];
+ Selection = [ PossibleNone ? '||-' : $SelectObj.val() ];
SelectionLength = 1;
}
When you create a Dynamic Field of type (Reference) Agent the Empty value option doesn't work at all, which causes the alphabetically first agent to be selected automatically.
I reproduced ths on ov270
This is my DF configuration:
This is the result (it looks the same e.g. in a Process Activity Dialog or in AgentTicketPhone):