-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DynamicField Reference Agent: Empty value doesn't work #3719
Comments
Motivated by ITSMConfigurationManagement Issue #19.
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:
sub BuildSelection {
[...]
if ( !defined $Param{SelectedID} && !defined $Param{SelectedValue} ) {
$Param{SelectedID} = '';
}
[...]
} |
For the interested reader, the place where the mentioned sorting takes place is here: otobo/Kernel/Output/HTML/Layout.pm Lines 5920 to 5926 in 9670cb1
|
Is reproducible with a standard dropdown dynamic field including
" ) is sorted in front of the empty value (- ). (See also backend sorting above.)
|
steps to reproduce:
Expected Behaviour:DF dropdown has empty value pre-selected Observed Behaviour:DF dropdown has one of the weird values from above pre-selected , eg '"-"' root causeCombination of the backend sorting and the way the frontend handles selection (see above comments) possible approaches
|
option a) patch the backend Kernel/Output/HTML/Layout.pmdiff --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';
} option b) - hack the frontend Core.UI.InputFields.jsdiff --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:
![image](https://private-user-images.githubusercontent.com/87359203/359117095-6591c1ac-a2e5-4fcb-a226-03d4272ad779.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxODYyMDMsIm5iZiI6MTczOTE4NTkwMywicGF0aCI6Ii84NzM1OTIwMy8zNTkxMTcwOTUtNjU5MWMxYWMtYTJlNS00ZmNiLWEyMjYtMDNkNDI3MmFkNzc5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDExMTE0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJiOTc3NTVjYmQxZTE2NjY1ODlhYTI1MTdlOGE1MGI5NDljMzlmNzYyOTBmOTEwYmIxZGVlNTJmY2ZhNDFlYTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.rxYEnzCblteIn3CKA-IHC39AxQ_Ie44OZD2v8aQhiII)
This is the result (it looks the same e.g. in a Process Activity Dialog or in AgentTicketPhone):
![image](https://private-user-images.githubusercontent.com/87359203/359117287-8082b520-b157-4e4c-88a1-dcec2daa115a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxODYyMDMsIm5iZiI6MTczOTE4NTkwMywicGF0aCI6Ii84NzM1OTIwMy8zNTkxMTcyODctODA4MmI1MjAtYjE1Ny00ZTRjLTg4YTEtZGNlYzJkYWExMTVhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDExMTE0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMzNGEwMzlkODVlNWMxMDMzNWE3ZjZiZjc3ZmVlZDI2NGYzYTU5MGU1YTRhMzk4ZDY4MjRmZDYzOGFiYWUyNDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.OrWsc_Y90obXH4sMY7X904riQfTC7qXWZYUGFUyy350)
The text was updated successfully, but these errors were encountered: