[Rt-commit] rt branch, 4.6/selectize-multiple-user-inputs, updated. rt-4.4.4-81-gc70b4815a

? sunnavy sunnavy at bestpractical.com
Fri Jun 21 16:05:09 EDT 2019


The branch, 4.6/selectize-multiple-user-inputs has been updated
       via  c70b4815ae7e53aefced891a2eb771e7b27a8e68 (commit)
      from  29c47233ed058ca9cf5d157081b26a2d6c9d4281 (commit)

Summary of changes:
 share/html/Helpers/Autocomplete/Users | 13 ++++++++++++-
 share/static/js/autocomplete.js       |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit c70b4815ae7e53aefced891a2eb771e7b27a8e68
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 22 03:24:30 2019 +0800

    Make values of fields specified in $UserSearchFields searchable in selectize
    
    Unlike autocomplete in jQuery UI, selectize filters its options at
    client side, so we need to add enough info there to bypass the filter.
    
    E.g. when WorkPhone is added to $UserSearchFields, a user search like
    "1234" could retrieve users with that string in WorkPhone via the AJAX
    call.  But since label/value doesn't contain "1234", selectize won't
    show these user options in the UI, which is really bad.

diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index 7051a653a..082027de0 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -108,7 +108,18 @@ $users->SimpleSearch( Privileged => $privileged,
 
 my @suggestions;
 while ( my $user = $users->Next ) {
-    my $suggestion = { id => $user->id, label => $user->Format, value => $user->$return };
+    my @searched_values;
+    for my $field ( keys %{ RT->Config->Get('UserSearchFields') } ) {
+        if ( $field =~ /^CF\.(?:\{(.*)}|(.*))$/ ) {
+            push @searched_values, $user->CustomFieldValuesAsString( $1 || $2 );
+        }
+        else {
+            push @searched_values, $user->$field;
+        }
+    }
+    my $text = join "\n", grep defined $_, @searched_values;
+
+    my $suggestion = { id => $user->id, label => $user->Format, value => $user->$return, text => $text };
     $m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, user => $user );
     push @suggestions, $suggestion;
 }
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index c56268448..9834ca6d6 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -55,7 +55,7 @@ window.RT.Autocomplete.bind = function(from) {
                 options: options ? JSON.parse(options) : null,
                 valueField: 'value',
                 labelField: 'label',
-                searchField: ['label', 'value'],
+                searchField: ['label', 'value', 'text'],
                 create: true,
                 closeAfterSelect: true,
                 maxItems: null,

-----------------------------------------------------------------------


More information about the rt-commit mailing list