[Rt-commit] rt branch 5.0/selectize-bypass-client-filtering created. rt-5.0.2-221-g531b217adb
BPS Git Server
git at git.bestpractical.com
Wed May 4 14:51:41 UTC 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/selectize-bypass-client-filtering has been created
at 531b217adb726c8ca49183afccac49acc0c85432 (commit)
- Log -----------------------------------------------------------------
commit 531b217adb726c8ca49183afccac49acc0c85432
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed May 4 15:33:23 2022 +0800
Bypass selectize's client filter by showing all search results
Previously in 9d7043e25e we added all search field values to results to
bypass selectize's client filter, which is not good enough because the
client filter doesn't do exact match, e.g. "foo bar" matches both "foo
bar" and "foo d bar", and the latter is not supposed to match.
This commit changes the logic to clear existing options(might be
outdated) first and then show all results from server. It also covers
both user and principal autocomplete.
diff --git a/share/html/Helpers/Autocomplete/Principals b/share/html/Helpers/Autocomplete/Principals
index f036af6fa1..9d1e49adc8 100644
--- a/share/html/Helpers/Autocomplete/Principals
+++ b/share/html/Helpers/Autocomplete/Principals
@@ -125,7 +125,7 @@ $m->callback( CallbackName => "ModifyGroupsLimit", Groups => $groups, Term => $t
my @suggestions;
while ( my $user = $users->Next ) {
- my $suggestion = { id => $user->id, label => $user->Format, value => $user->EmailAddress || $user->Name };
+ my $suggestion = { id => $user->id, label => $user->Format, value => $user->EmailAddress || $user->Name, text => $term };
$m->callback(
CallbackName => "ModifySuggestion",
suggestion => $suggestion,
@@ -143,7 +143,7 @@ while ( my $group = $groups->Next ) {
# parsing problems
my $value = $delim && $label =~ $delim ? 'group:' . $group->id : $label;
- my $suggestion = { id => $group->id, label => $label, value => $value };
+ my $suggestion = { id => $group->id, label => $label, value => $value, text => $term };
$m->callback(
CallbackName => "ModifySuggestion",
suggestion => $suggestion,
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index 5d7d260bd3..a3237e1fe6 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -112,18 +112,7 @@ $m->callback( CallbackName => "ModifyUsersLimit", Users => $users, Term => $term
my @suggestions;
while ( my $user = $users->Next ) {
- my @searched_values;
- for my $field ( sort 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 };
+ my $suggestion = { id => $user->id, label => $user->Format, value => $user->$return, text => $term };
$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 d4b1eb4711..c967050ddf 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -64,7 +64,7 @@ window.RT.Autocomplete.bind = function(from) {
items: items ? JSON.parse(items) : null,
valueField: 'value',
labelField: 'label',
- searchField: ['label', 'value', 'text'],
+ searchField: ['text'],
create: true,
closeAfterSelect: true,
maxItems: null,
@@ -92,21 +92,22 @@ window.RT.Autocomplete.bind = function(from) {
self.unlock();
},100);
},
- load: function(input, callback) {
- if (!input.length) return callback();
+ load: function(query, callback) {
+ if (!query.length) return callback();
jQuery.ajax({
url: RT.Config.WebHomePath + '/Helpers/Autocomplete/' + what,
type: 'GET',
dataType: 'json',
data: {
delim: ',',
- term: input,
+ term: query,
return: wants
},
error: function() {
callback();
},
success: function(res) {
+ input[0].selectize.clearOptions();
callback(res);
}
});
diff --git a/t/web/case-sensitivity.t b/t/web/case-sensitivity.t
index deb4fd0e90..6cb0f1579a 100644
--- a/t/web/case-sensitivity.t
+++ b/t/web/case-sensitivity.t
@@ -25,7 +25,7 @@ $m->login;
[ { id => 14,
"value" => "root\@localhost",
"label" => "root (Enoch Root)",
- "text" => join( "\n", 'root at localhost', 'root', 'Enoch Root', ),
+ "text" => 'eNo',
}
]
);
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list