[Rt-commit] rt branch, 5.0/fix-duplicate-ids, updated. rt-5.0.0alpha1-162-g7ff97f561a
Michel Rodriguez
michel at bestpractical.com
Wed May 6 16:44:49 EDT 2020
The branch, 5.0/fix-duplicate-ids has been updated
via 7ff97f561a2409baacce4d45223219f1053cbe10 (commit)
from 9be3c633472aa15eb1d320eb15d4b469de83db24 (commit)
Summary of changes:
share/html/Elements/SelectOwnerAutocomplete | 27 +--------------------------
share/static/js/util.js | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 26 deletions(-)
- Log -----------------------------------------------------------------
commit 7ff97f561a2409baacce4d45223219f1053cbe10
Author: michel <michel at bestpractical.com>
Date: Wed May 6 22:07:47 2020 +0200
Refactor autocomplete for the Owner field in search results.
Remove ID from owner field, replace it with a class.
Move the JS function to util.js. The query parameter is passed as the
data-query attribute in the HTML. The name of the helper ("Owner"
in this case) is passed as the data-field attribute, so the function
can be re-used.
diff --git a/share/html/Elements/SelectOwnerAutocomplete b/share/html/Elements/SelectOwnerAutocomplete
index e7b31e94ee..b2d3896886 100644
--- a/share/html/Elements/SelectOwnerAutocomplete
+++ b/share/html/Elements/SelectOwnerAutocomplete
@@ -73,32 +73,7 @@ my $query = $m->comp('/Elements/QueryString',
limit => $limit,
);
-my $id = $TicketObj ? "autocomplete-$Name-" . $TicketObj->Id : $Name;
</%INIT>
-<input type="text" id="<% $id %>" name="<%$Name%>" value="<% $value %>" class="form-control input-<% $Name %>" />
-<script type="text/javascript">
- jQuery(function() {
- var cache = {};
- jQuery('#<% $id %>').autocomplete({
- minLength: 2,
- source: function(request, response) {
- if ( request.term in cache ) {
- response( cache[ request.term ] );
- }
- else {
- jQuery.ajax({
- url: RT.Config.WebPath + "/Helpers/Autocomplete/Owners?"+<% $query|n,j %>,
- dataType: "json",
- data: request,
- success: function( data ) {
- cache[ request.term ] = data;
- response( data );
- }
- });
- }
- }
- });
- });
-</script>
+<input type="text"name="<%$Name%>" value="<% $value %>" class="form-control rt-autocomplete" data-field="Owners" data-query="<% $query %>"/>
diff --git a/share/static/js/util.js b/share/static/js/util.js
index fdf6a1941e..b75be0a520 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -978,3 +978,32 @@ function toggle_bookmark(url, id) {
jQuery('.toggle-bookmark-' + id).replaceWith(data);
});
}
+
+jQuery(function() {
+ var cache = {};
+ jQuery('input.rt-autocomplete').each(
+ function () {
+ var field = jQuery( this ).attr( 'data-field' );
+ var query = jQuery( this ).attr( 'data-query' );
+ jQuery( this ) .autocomplete({
+ minLength: 2,
+ source: function(request, response) {
+ if ( request.term in cache ) {
+ response( cache[ request.term ] );
+ }
+ else {
+ jQuery.ajax({
+ url: RT.Config.WebPath + '/Helpers/Autocomplete/' + field + '?' + query,
+ dataType: "json",
+ data: request,
+ success: function( data ) {
+ cache[ request.term ] = data;
+ response( data );
+ }
+ });
+ }
+ }
+ });
+ });
+});
+
-----------------------------------------------------------------------
More information about the rt-commit
mailing list